Jump to content
  • Advertisement
Sign in to follow this  
Rattrap

g++ help

This topic is 4864 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I tried compiling a little bit of code in g++ under cygwin. MSVC 2003, produces a file about 24kb. g++ produces a file around 465kb. I'm figuring the difference is because of compiler flags, which I am very ignorant of the gcc/g++ ones. Does anyone know some quick flags for gcc/g++ that should help? Right now I'm just doing: g++ -03 main.cpp which is successfully compiling. [Edited by - Rattrap on July 22, 2005 2:46:48 PM]

Share this post


Link to post
Share on other sites
Advertisement
It's nothing to do with compiler flags, it's to do with static vs dynamic C++ libraries.

I am assuming that you are using the C++ standard library (if you're not, it should make little difference).

If you are, then g++ will normally statically link some of it.

MSVC *may* use a DLL for its C++ library - thus reducing the binary size.

Ensure that you are comparing a stripped binary (i.e. one without debugging info).

Using -O3 is not generally recommended - more than 1 -O apparently may result in code that doesn't necessarily do quite what you expect (although I've never experienced this).

In any case, the difference between -O and -O3 is negligible in most cases.

---

Note that in gcc, you can enable debugging and optimisation if you want but this does not normally make a lot of sense, as optimised binaries can't be debugged meaningfully because stuff that you're trying to go through in the debugger may be optimised out.

Mark

Share this post


Link to post
Share on other sites
Try the -Os flaag for the 'fastest/smallest' optimization. Also, which version of gcc are you using? Earlier versions might not have as good an optimizer.

Maybe your file is so big because you have symbolic debug info turned on? I'm not sure what the default is, but if it's on then the program size should be much bigger.

As far as I know MSVC links wth the static standard library by default, though using the DLL is an option.

Share this post


Link to post
Share on other sites
I'm not trying to do debug, I was just seeing if the code would compile under another compiler. The MSVC 2003 generated file was generated in release mode. From what I can tell, it is staticly linking to the Single-Threaded C++ standard library. I also tried the multithreaded C++ library, the file size went up about 12k, but it is still no where close to the 400+kb executable that g++ is making.

Also the g++ version is 3.4.4

[edit]
Also, if I switch to DLL linking in MSVC, the file drops to about 3kb.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Try the strip -program (strip ). I'm not too sure what it actually does, but it seems to work :)

Share this post


Link to post
Share on other sites
Quote:
Original post by Anonymous Poster
... I'm not too sure what it actually does, but it seems to work :)


It strips the executable from debug information (symbols).

Share this post


Link to post
Share on other sites
I tried the -g option (enabling debug), and the file got about 100k bigger, so it looks like debug is probably disabled.

I tried the strip program, and it cut the file size in about half (down to around 250kb).

Share this post


Link to post
Share on other sites
There are ways to further shrink your program... strip is a big one, there's some compiler flags you can use as well. However, a good bit of that extra chunk is library code that's been linked statically rather than dynamically. The good thing is that this increase should not be seen as a percentage increase, but rather an absolute increase (probably along with a percentage increase or DEcrease, which I don't know)

Share this post


Link to post
Share on other sites
I tried removing #include <iostream> from my program (I wasn't actually using anything in there at the moment, I put it in by force of habit). The g++ compiled app dropped to about 8kb (pre stripping). 2kb after. What it looks like is happening is, g++ is adding a bunch of code from the standard library that isn't being used at all, or at least its not removing unused code.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!