I can't seem to disable dynamic linking. How do I do this? I've tried the following:

babbage-dasnyder 19% mips-unknown-linux-gnu-g++ -static -static-libgcc hello.cpp
babbage-dasnyder 20% file hello
hello: ELF 32-bit MSB MIPS-I executable, MIPS, version 1 (SYSV), for GNU/Linux 2.4.18, dynamically linked (uses shared libs), not stripped

But as you can see, the binary is still dynamically linked. What's going on here?

Well from what I know if you use shared libs (as it is stated there) than don't expect your library to be completely statically linked.. it is not dependent on how you compile or link your code but how the libraries you use are made. As simple as that. A compiler cannot and will not "import" code from shared libraries to put it in your binary such that all external binary dependencies vanish... still your library can be statically linked to any application that are compiled to use it and then the remaining dynamic links for the application will be those of your static lib and any others... this is unavoidable, as far as I know. Learn to live with it, minimize external dependencies and use static standard libraries only if you want to avoid trouble with having to ship your applications with a bunch of dependencies on installation.

Check if your gcc is set to take static libraries for the standard C++ libraries and not shared ones (which I doubt), as I assume hello.cpp in this case is very simple, that would be the only reason why the compiler could not statically link everything.

This article has been dead for over six months. Start a new discussion instead.