[CMake] statically linking libstdc++ problem.

Brad King brad.king at kitware.com
Wed Jun 1 09:35:19 EDT 2005


christopher at baus.net wrote:
> I've run into a problem where users are not able to run my binary on
> certain versions of Linux that don't have the same version of libstdc++
> that I used to build the executable.  My plan was to statically link
> libstdc++, but I believe it is impossible with gcc unless glibc is
> statically linked which causes problems domain resolution.  The problem is
> explained in detail here; http://www.upl.cs.wisc.edu/~psilord/blog/2.html
> 
> The only solution I've come up with is to call collect2 (the undocumented
> gcc linker) directly.  I'm at a loss trying to find a way to do this
> cleanly with CMake, and I was hoping one of the gurus here could help me
> out.

I regularly build binaries that are linked shared to libc but statically 
to libstdc++.  The GCC library directory has both a static and a shared 
libstdc++, but the linker always favors the shared version.  There are 
two approaches:

1.) Build a GCC compiler with the --disable-shared option to skip 
building the shared libstdc++.

2.) Create a directory that contains a symlink to the static version of 
the library and then use the LINK_DIRECTORIES command to add it to the 
link path.  Then the linker will find the static version and use it.

Both of these approaches require modifications by hand on the system 
building the package.  I've found this acceptable because it is only 
needed on the system where I build the binary that will be distributed.

-Brad


More information about the CMake mailing list