How do I specify linker flags to be used in shared library build [cmake]

2.6k views Asked by At

I am running a build using cmake using the Meego 1.2 toolchain (long story). This particular toolchain requires the --sysroot option to be used to find any libraries it requires.

set (CMAKE_CXX_FLAGS "-fpermissive")
set (CMAKE_CXX_LINK_FLAGS "--sysroot=${INTEL_GRAPHICS_SDK_BASE}/sdk")
set (CMAKE_CXX_FLAGS_DEBUG "-g")

These options allow the cmake initial compiler checks to pass, but when producing a shared library during the build it looks like ld is being called without any of the options specified.

Is there a different cmake variable that needs to be set to specify the sysroot for shared libraries?

The error I am getting is

/usr/lib/madde/linux-i686/toolchains/meego-1.2-sdk-ia32-toolchain-1.0-linux_i686/i586-meego-linux-gnu/bin/../lib/gcc/i586-meego-linux-gnu/4.5.1/../../../../i586-meego-linux-gnu/bin/ld: crti.o: No such file: No such file or directory
collect2: ld returned 1 exit status
2

There are 2 answers

0
Apteryx On

You can use the CMAKE_SHARED_LINKER_FLAGS CMake option (set by passing -DCMAKE_SHARED_LINKER_FLAGS='-L/some/path' or any linker flags you need to your cmake invocation). For the (very brief) reference, see: https://cmake.org/cmake/help/latest/variable/CMAKE_SHARED_LINKER_FLAGS.html#cmake-shared-linker-flags.

0
Fei On

Since you're using cross compiler tool chain, why not just set CMAKE_CXX_COMPILER and pass those --sysroot= options to g++ (or gcc) directly?

There's also a flag named CMAKE_EXE_LINKER_FLAGS with below explanation:

CMAKE_EXE_LINKER_FLAGS

   Linker flags used to create executables.

   Flags used by the linker when creating an executable.