Linux gcc cc1:内存分配不足
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11289002/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
gcc cc1: out of memory allocating
提问by user1336117
I am trying to compile a source code in my BeagleBoard with Angstrom Linux. Yesterday I was able to compile my code. But today I can not compile the code and it says:
我正在尝试使用 Angstrom Linux 在我的 BeagleBoard 中编译源代码。昨天我能够编译我的代码。但是今天我无法编译代码,它说:
ccl: out of memory allocating 268439608 bytes after a total of 405504 bytes
make *** [getimagefromcam1.o] Error 1
My compilation string is:
我的编译字符串是:
gcc getimagefromcam1.c `pkg-config --cflags --libs opencv` -o getimagefromcam1 -lpthread
Code is:
代码是:
#include <cv.h>
#include <highgui.h>
#include <cxcore.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
CvCapture* camera = cvCreateCameraCapture(0); // Use the default camera
IplImage* frame = 0;
IplImage img;
cvSetCaptureProperty(camera,CV_CAP_PROP_FRAME_WIDTH,2016) ;
cvSetCaptureProperty(camera,CV_CAP_PROP_FRAME_HEIGHT,1512);
frame = cvQueryFrame(camera); //need to capture at least one extra frame
frame = cvQueryFrame(camera);
if (frame != NULL) {
printf("got frame 1\n\r");
cvSaveImage("webcam1.jpg", frame,0);
} else {
printf("Null frame 1\n\r");
}
frame = cvQueryFrame(camera); //need to capture at least one extra frame
frame = cvQueryFrame(camera);
if (frame != NULL) {
printf("got frame 1\n\r");
cvSaveImage("webcam1.jpg", frame,0);
} else {
printf("Null frame 1\n\r");
}
cvReleaseCapture(&camera);
return 0;
}
when I write "free" is says
当我写“免费”时说
total used free shared buffers cached
Mem: 241260 221256 20004 0 13748 116184
-/+ buffers/cache: 91324 149936
Swap: 0 0 0
How can I solve it?
我该如何解决?
采纳答案by Jonas Sch?fer
You're obviusly out of memory there (268439 > 221256
). Now you have two options:
很明显,您的内存不足 ( 268439 > 221256
)。现在你有两个选择:
Create a temporary swap filelike this. It boils down to:
su - root # for one GB of swap dd if=/dev/zero of=tmpswap bs=1024 count=1M mkswap tmpswap swapon tmpswap
I would opt for this way as a quick fix, not to mention that you really should have a bit of swap with that small amount of memory.
Read the article if you want to make this change permanent, it contains some valuable hints regarding permissions and fstab.
Try to simplify your code so that
cc1
does not need so much memory. No idea how to do that though.
像这样创建一个临时交换文件。归结为:
su - root # for one GB of swap dd if=/dev/zero of=tmpswap bs=1024 count=1M mkswap tmpswap swapon tmpswap
我会选择这种方式作为快速解决方案,更不用说你真的应该用那么少量的内存进行一些交换。
如果您想让此更改永久化,请阅读这篇文章,其中包含一些有关权限和 fstab 的宝贵提示。
尝试简化您的代码,以便
cc1
不需要太多内存。不知道如何做到这一点。