11

When I try to build this project with cmake and gcc on a 64-bit linux (debian) machine, I get an error from the linker:

Linking C executable ../../../../cpsadamsx
/home/dala/lib64/libSimTKcommon.so: undefined reference to `dlopen'
/home/dala/lib64/libSimTKcommon.so: undefined reference to `dlclose'
/home/dala/lib64/libSimTKcommon.so: undefined reference to `dlerror'
/home/dala/lib64/libSimTKcommon.so: undefined reference to `dlsym'
collect2: ld returned 1 exit status
make[2]: *** [cpsadamsx] Error 1
make[1]: *** [sundials/examples/cpodes/serial/CMakeFiles/cpsadamsx.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....

Apparently dlopen, dlclose, dlerror and dlsym are references to libdl.so. I have that library in /lib64/libdl.so.2, but why is it not found?

Would it have been a normal './configure; make; make install'-path I could have set the LIBS variable and issued the configure command like this (I think):

export LIBS=-ldl && ./configure

But how do I do it now?

UPDATE:

So it seems that the (or at least a) library is found, but does not contain the symbols in question. Perhaps it tries with the 32-bit library in /lib?

Is there a way to disassemble /lib64/libdl.so.2 to make sure it does have the references dlopen etc?

The problem now seems to guide the build tools to the correct version of the library.

dala
  • 1,975
  • 3
  • 14
  • 15

3 Answers3

37

As this question is showing up on google and both answers won't point to the correct solution here it is:

In your CMakeLists.txt add ${CMAKE_DL_LIBS} to link against idl. It should look similar to this:

target_link_libraries(ExpandableTest
    ${CMAKE_DL_LIBS}
    Expandable
    ExpandableTestLibrary
)
Mythli
  • 5,995
  • 2
  • 24
  • 31
1

Probably you need to add target_link_libraries() - see link text

dimba
  • 26,717
  • 34
  • 141
  • 196
  • That might work, but it is not "my" project, so preferably I do not want to edit the CMakeLists.txt files. – dala Aug 13 '09 at 21:16
0

Add this in CMakeLists.txt and it should work:

SET (CMAKE_CXX_FLAGS  "${CMAKE_CXX_FLAGS} -ldl")
usr1234567
  • 21,601
  • 16
  • 108
  • 128
Cherif
  • 113
  • 1
  • 3