Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile C++ for all linux distributions

Tags:

c++

linux

How can i compile my C++ files to work on ALL linux distributions. The machine that i'll compile them on is Ubuntu 10.10

If i compile them on Ubuntu 10.10, will they work on other Distros like ubuntu, fedora, debian, non debian distros.. etc?

like image 804
Daniel Avatar asked Dec 06 '10 08:12

Daniel


3 Answers

% 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.

like image 133
akira Avatar answered Nov 10 '22 07:11

akira


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!

like image 31
Chris Huang-Leaver Avatar answered Nov 10 '22 07:11

Chris Huang-Leaver


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

like image 2
Nemanja Trifunovic Avatar answered Nov 10 '22 07:11

Nemanja Trifunovic