gcc cc1: out of memory allocating
Asked Answered
U

2

9

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:

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?

Underpants answered 2/7, 2012 at 6:55 Comment(1)
What version of gcc are you using? Try to upgrade to a recent version (e.g. 4.7 or at least 4.6).Almost
L
17

You're obviusly out of memory there (268439 > 221256). Now you have two options:

  1. Create a temporary swap file like 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.

  2. Try to simplify your code so that cc1 does not need so much memory. No idea how to do that though.

Leptospirosis answered 2/7, 2012 at 7:2 Comment(6)
It solved but here I see a new error: attempt to access beyond end of device mmcblk0p2: rw=0, want=34359738368, limit=15433728 attempt to access beyond end of device mmcblk0p2: rw=0, want=34359738368, limit=15433728Underpants
Sounds not good, but I do not know where hat could come from.Affiance
I'd suggest using fallocate instead of dd as it's considerably faster: fallocate -l 1G tmpswapPreferment
@Preferment Oh nice, I did not know that. I know that truncate does not work because it creates a sparse file which swapon does not like (understandably). Will edit.Affiance
The advice about fallocate is not correct: unix.stackexchange.com/a/294605/229227Lennalennard
@Lennalennard Indeed. Fixed.Affiance
O
0

If you use Clion to build you program, just check Build>>Clean, and rebuild your program, then all error missing.

Oneal answered 29/6, 2022 at 3:4 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Emersonemery

© 2022 - 2024 — McMap. All rights reserved.