[CMake] Correct way to link with libstdc++ from non-C++ project?

Jed Brown jed at 59A2.org
Thu Sep 15 12:39:17 EDT 2011


Suppose project Foo depends on a library Bar that uses C++ internally, but
was not properly linked, so foo would need to be linked with

1. $CC -shared -o libfoo.so *.o -lbar -lstdc++

or

2. $CXX -shared -o libfoo.so *.o -lbar


Note that

find_library (LIBSTDCXX NAMES stdc++)

does not work because this library is often not in a public directory, so a
full path cannot be resolved. My understanding is that current recommended
practice is to use option 2 above, but this breaks down if Foo also needs to
link some Fortran libraries because you can't link using both the C++
compiler and the Fortran compiler.

If the Fortran and C++ compilers come from the same suite, passing a literal
"-lstdc++" will generally work, but this is not robust if they come from
different suites. Is there a way to mark a library as depending on a
language or some other internal compiler library, so that CMake will sort
out how to do the multi-language link in the same way it does if the project
has source files in each language?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20110915/0c47c626/attachment.htm>


More information about the CMake mailing list