5

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:

  • How to remove /path/to/libs/ for 4. and 5.? Something to do with LD_LIBRARY_PATH?
  • Auto-answered: I get what means 1. Search for libc.so.6 in that path. But what about 2. and 3.? locate linux-gate.so.1 gives nothing. Why 3. has no => symbol? (found answer here)
Community
  • 1
  • 1
Borzh
  • 5,069
  • 2
  • 48
  • 64

2 Answers2

4

Ok found the answer:

set( CMAKE_SKIP_BUILD_RPATH true )

That did it.

Borzh
  • 5,069
  • 2
  • 48
  • 64
-1

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.

ToniBig
  • 836
  • 6
  • 21
  • 1
    The question was how to remove hardcoded /path/to/libs/ and leave only lib1.so/lib2.so to search with LD_LIBRARY_PATH. Check out my answer, that fix it. Now, how to copy library with CMake? – Borzh Jul 27 '14 at 20:33
  • 2
    @Borzh I just had the feeling that what you saw, was not an actual problem. Still you are right. What you answered will remove the rpath entries from the start. If you want to copy your library using CMake use either ``FILE COPY`` or ``INSTALL``. – ToniBig Jul 28 '14 at 20:00