树莓派3 Raspbian系统编译iotivity-node失败求助
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 toCONF_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:
You should see the swap size listed as 2GB now.free -h
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
npmto build, run:npm rebuild --jobs=1 - If you're running
makedirectly, use:
This reduces memory usage significantly by compiling one target at a time.make -j1
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
sshdif 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

