You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

树莓派3 Raspbian系统编译iotivity-node失败求助

Fixing "virtual memory exhausted" When Compiling iotivity-node on Raspberry Pi 3

Hey there, let's get this compilation issue sorted out for you! The error virtual memory exhausted: Cannot allocate memory is a classic sign that your Raspberry Pi 3 doesn't have enough RAM to handle the resource-heavy compilation of the constants.o target in iotivity-node. Your Ubuntu laptop works because it has far more available memory compared to the Pi 3's default 1GB RAM.

Here are three actionable fixes to resolve this:

1. Expand Swap Space (Virtual Memory)

The Pi's default swap space is usually too small for large compilation tasks. Here's how to increase it:

  • Stop the active swap service first:
    sudo dphys-swapfile swapoff
    
  • Edit the swap configuration file:
    sudo nano /etc/dphys-swapfile
    
  • Find the line CONF_SWAPSIZE=100 (or similar) and change it to CONF_SWAPSIZE=2048 (to allocate 2GB of swap space).
  • Save the file (Ctrl+O, then Enter) and exit nano (Ctrl+X).
  • Reinitialize and start the swap service:
    sudo dphys-swapfile setup
    sudo dphys-swapfile swapon
    
  • Verify the change with:
    free -h
    
    You should see the swap size listed as 2GB now.

2. Limit Parallel Compilation Jobs

By default, make uses all available CPU cores to speed up compilation, but this eats up more memory. Force it to use only one core at a time:

  • If you're using npm to build, run:
    npm rebuild --jobs=1
    
  • If you're running make directly, use:
    make -j1
    
    This reduces memory usage significantly by compiling one target at a time.

3. Free Up Existing Memory Before Compiling

Close any unnecessary background processes to free up RAM:

  • If you're using the desktop environment, close browsers, media players, or other non-essential apps.
  • You can also stop unused system services temporarily (be careful not to stop critical ones like sshd if you're accessing the Pi remotely):
    sudo systemctl stop lightdm  # Stops the desktop environment, if you're using it
    

After trying one or more of these fixes, restart your compilation process—it should complete without the memory exhaustion error.

内容的提问来源于stack exchange,提问作者cchhsu

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:12:27