CMake set library search path fails in testCXXCompiler

2k views Asked by At

I built my own GCC and libraries and put the libraries in /opt/gcc-4.6.2/lib so generically-named libraries like libstdc++ do not interfere with other parts of the system. This means I have to specify the library search path manually:

$> g++-4.6.2 -L/opt/gcc-4.6.2/lib input.cpp

When trying to get my project to build with CMake, I can't seem to figure out how to tell CMake to search that library. The documentation says to use CMAKE_LIBRARY_PATH, which I set on the line used to generate my Makefiles:

$> cmake .. -DCMAKE_CXX_COMPILER=g++-4.6.2 \
            -DCMAKE_LIBRARY_PATH=/opt/gcc-4.6.2/lib

This, however, fails on the simple program compilation test:

# blah blah blah...

/usr/local/bin/g++-4.6.2
CMakeFiles/cmTryCompileExec.dir/testCXXCompiler.cxx.o -o cmTryCompileExec
-rdynamic

/usr/bin/ld: cannot find -lstdc++

# blah blah blah...

I can't seem to find the voodoo magic needed to make CMake emit -L/opt/gcc-4.6.2/lib for the test compilation (I know CMAKE_LIBRARY_PATH works after the project is built). How can I force CMake to use an alternative library path to link the test executables?

1

There are 1 answers

0
arrowd On

Hmm, i'm not familiar with how gcc builds itself, but i suppose that it should know where to search for it's libs. Maybe you should try cross-compilation.

Also, CMAKE_LIBRARY_PATH will not help your problem, since it set libraries search path only for CMake, not for compiler.

So, i don't see any other way except setting CMAKE_CXX_FLAGS or CMAKE_EXE_LINKER_FLAGS to -L/opt/gcc-4.6.2/lib.