Borzh
Borzh

Reputation: 5205

cmake link to shared libraries without using full path

I have following CMakeLists.txt:

set( PROJECT_LINK_LIBS lib1.so lib2.so )
link_directories( path/to/libs ) # lib1.so and lib2.so are there.

add_library( ${PROJECT_NAME} SHARED ${PROJECT_SOURCES} )
target_link_libraries( ${PROJECT_NAME} ${PROJECT_LINK_LIBS} )

Which compiles and links fine.

But when I do:

ldd -d mylib.so

I get:

  1. libc.so.6 => /lib/i386-linux-gnu/libc.so.6 (0xf529b000)
  2. linux-gate.so.1 => (0xf777a000)
  3. /lib/ld-linux.so.2 (0xf777b000)
  4. lib1.so => /path/to/libs/lib1.so (0xf56a2000)
  5. lib2.so => /path/to/libs/lib2.so (0xf548f000)

My questions are:

Upvotes: 5

Views: 6094

Answers (2)

ToniBig
ToniBig

Reputation: 836

Do you have an actual problem or are you just confused with the out put of ldd? To answer your question: If you successfully compile and link your library on Linux, the full paths to your external libraries will be stored. If you now copy or install (using CMake) your library, the full libraries paths will be stripped. Now, you will have to make sure that the correct paths are provided by LD_LIBRARY_PATH or that the external libs reside in the same folder your library is in.

Upvotes: -1

Borzh
Borzh

Reputation: 5205

Ok found the answer:

set( CMAKE_SKIP_BUILD_RPATH true )

That did it.

Upvotes: 4

Related Questions