ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How can I compile a C++ application using GCC so that the binary can be run on multiple Linux distribution? Depending on where I am compiling and where I am running, I get runtime errors about the libc .o file, or files. When I compile code on Linux, the binary is always so small compared to a binary on other systems like Windows or Mac but it looks like that is because very little is being linked into it. Is it possible to link "basic" C/C++ language libraries into the binary? Certain binary-only closed-source programs (like Id Software games for example) seem to function properly across distributions. Sorry if I am missing some fundamental aspect of the Linux architecture. If someone could explain it, I would certainly appreciate it.
-Brandon R
Last edited by spaaarky21; 04-10-2007 at 02:02 AM.
You need to statically link the libraries or add code that makes sure the libraries are present before it tries to run, and takes appropriate action.
gcc usues dynamic linking by default - which is why the binaries are so small compared with those proprietary OS's. It is also the reason for "dependency hell" you may have experienced with rpm installations, and the extensive use of package managers like yum.
Usually, you would want to set up yum, and apt, compatible packages to distribute your software widely. If lots of folk find your work useful, then this will take on a life of its own.
It is not, however, possible to guarantee it will work with every linux distribution possible. There are just too many variables.
You need to statically link the libraries or add code that makes sure the libraries are present before it tries to run, and takes appropriate action.
gcc usues dynamic linking by default - which is why the binaries are so small compared with those proprietary OS's. It is also the reason for "dependency hell" you may have experienced with rpm installations, and the extensive use of package managers like yum.
Dependency hell is the reason I had to upgrade to Fedora Core 4 instead of just upgrading MySQL.
Well, I think static linking will do. I did some searching before I posted but wasn't looking with the right words. Apparently GCC's -static flag should be just about all I need. I don't plan on distributing packages far and wide, just running off of a flash drive on multiple distros, so this should be the best option.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.