LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-21-2014, 01:59 PM   #1
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Rep: Reputation: 255Reputation: 255Reputation: 255
gcc: not sufficient memory to compile, even with -O2 ?


Hello, Good morning,

I would like to compile a C program with visibly not sufficiently enought main memory. My machine has the following 256MB DDR-333 SDRAM, 166MHz under Linux Debian Testing.

I have tried with the option -O2 but it still can not compile the C code.

I am out of luck.

I would be pleased if you could tell me how to compile with this given machine.

I hope so much that you would have any further ideas or tricks.

Thank you so much by advance.
 
Old 09-21-2014, 02:07 PM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,291

Rep: Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322Reputation: 2322
Check for adequate swap space, close off _everything_ not needed for the compile. I ran out once on a link - the compile was ok. I had 128M and 64M of swap, and it used them all before crapping out. Closing everything got me through, but it used 197MB of ram&swap - pretty close!

You need a console, runlevel 3, all background stuff closed. No X, no nothing.

If the gcc command breaks down, it's probably a problem with the software. If it's the link (ld), it may just be linked to too many libs.
 
Old 09-21-2014, 02:15 PM   #3
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
You probably do need more swap to be able to compile large programs or libraries on such a machine.
 
Old 09-21-2014, 02:22 PM   #4
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
+1 for swap.
Also, if it is your program, check the size of the source: a compilation unit shouldn't be bigger than a few hundred lines.
 
Old 09-21-2014, 02:50 PM   #5
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Original Poster
Rep: Reputation: 255Reputation: 255Reputation: 255
Thank you for first replies.

I am actually not using a swap (partition) on this machine. There is no swap, only ext2 with / and ext3 with /home. Ok. So let's bring a swap:

I could plug an USB harddrive of 1 TeraBytes. Format it to Swap (create it maybe with fdisk if it works) and edit the /etc/fstab to mount it as swap. (I have to check how on google).
Would you think that it would work, i.o.w. that gcc would work and would compile?

I looking forward to reading you.

Thank you in advance.
 
Old 09-21-2014, 03:07 PM   #6
metaschima
Senior Member
 
Registered: Dec 2013
Distribution: Slackware
Posts: 1,982

Rep: Reputation: 492Reputation: 492Reputation: 492Reputation: 492Reputation: 492
It should work, but I would put swap on the main HDD whenever possible, otherwise you'll have to turn it on manually every time. On such a low RAM machine you need swap. I only run without swap on machines with at least 2-4 GB of RAM.
 
Old 09-21-2014, 10:51 PM   #7
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Note: you can use swap-files too, no only swap-partitions.
 
Old 09-22-2014, 12:21 AM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,842

Rep: Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308Reputation: 7308
one additional comment: using -O2 will force the compiler to eat more memory, without optimization it needs less...
 
Old 09-30-2014, 02:00 PM   #9
Xeratul
Senior Member
 
Registered: Jun 2006
Location: UNIX
Distribution: FreeBSD
Posts: 2,657

Original Poster
Rep: Reputation: 255Reputation: 255Reputation: 255
Sorry for my relatively late answer. I have been quite busy.


I would like to thank you !!

This method of adding a swap was the key to success.

I used gparted, and created a swap partition on an 8gb pendrive.
I configured /etc/fstab and mount using swap -a when I need to compile (somtimes)

It works (no need of -O2 even)!! Just the swap is sufficient to compile. finally.

Thank you !!!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Failed to compile libatomic at the first time to compile gcc(step 5.5) clicdl Linux From Scratch 8 07-23-2013 05:20 AM
Why couldn't the gcc(version4.3.3) be used to compile the gcc(version3.3.2)? snc Linux - Newbie 6 01-24-2010 11:26 AM
Compile error, 'H5G_obj_t' does not name a type, is gcc 4.3 incompatible with gcc 3 ? samrat_rao Linux - Software 5 03-03-2009 02:28 PM
malloc(): memory corruption: in first stage compile of gcc for lfs 6.3 Skazi Linux From Scratch 1 11-03-2007 12:36 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:34 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration