开发者

Compile C++ for all linux distributions

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开发者_StackOverflow other Distros like ubuntu, fedora, debian, non debian distros.. etc?


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


Provided you only use the libraries listed in the Linux Standards Base, a dynamic executable should be fine.

For other libraries, either link with static versions of them, or ship dynamic libraries; I prefer the former.

I would personally recommend avoiding static-linking the C library, as this prevents some useful functionality provided by it working, for example the nss stuff..

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜