Compile C++ for all linux distributions Compile C++ for all linux distributions linux linux

Compile C++ for all linux distributions


% gcc -o foo foo.c -static

the resulting binary should work on most distros, given that it runs on the same architecture (64bit, 32bit, arm, mips etc).

the main point is: since you do not know what can be found on the target systems in advance, you have to bundle everything you can into either the binary you are shipping or in some kind of "chrooted" environment where you deploy external libs as well (stuff that can't be linked statically) and then have some kind of a wrapper to use your deployed libs instead of the system libs.


Although @akira answer will probably work for your case, it isn't the best solution. Most Linux distros have packing systems which retrieve the dependencies for you.

If you are serious about writing Linux software which is used on other people's boxes, you will need to look into 'GNU Autotools' which is what drives the ' ./configure && make all && make install ' thing which you will have run more than once by now!


It is much harder than it should be, at least for C++: http://www.trilithium.com/johan/2005/06/static-libstdc/