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.
Hi guys.
How can I compile my C++ program in a way that it dosen't use shared libraries like 'libstdc++'?
Few days ago, I give my program to one of my friends. After a while, he called me and say: "I can't run your program, it says that it want libstdc++6". The problem was he has libstdc++5, not 6.
So ... is there any way to bind this libraries inside of binary file? (like static libraries). I want a binary file which can run in any system, without dependence.
I don't know if you can force normally dynamic libraries to be directly included in your binary. But, you could just give your friend the source code and have him compile it himself. Or, your using debian so you might be able to create a .deb 'installer'? I don't know much about .deb's cause I use suse. Anyone else know?
Can you not compile with "-static"? Edit: I would assume, though, that this requires that static versions of the library files (possibly .a or .la files, rather than .so, but I'm not certain) need to exist on your system.
Yes, -static will normally require that libstdc++.a exist, though not all compilers (or versions) use the same name. The C++ RTLs aren't supposed to be "noticed" by the user in the sense of what their names are: the C++ compiler is supposed to handle everything related to its own RTL internally from compilation all the way through linking.
I don't have a problem creating static binaries with g++ in test situations. The main problem is it will greatly increase the size of your binary, usually to at least 1MB. Also, run-time exceptions won't propagate properly, but that only really matters if you're also using exception code.
ta0kira
PS If you use g++, type whereis libstdc++ and see if libstdc++.a shows up.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.