27

I am building a shared library that uses the dlopen and dlsym system calls. When I build, I get the error

undefined reference to `dlopen` 

How can I fix this?

3
  • 1
    It could be many reasons, when dlopen is not found during linking. One is that you doesn't link with dl library. You have good reputation, you definitely have searched this error message before posting a question. What have you tried? Commented Nov 12, 2015 at 22:15
  • 2
    Also, what about your code (CMakeLists.txt file)? You should provide it for get help. Commented Nov 12, 2015 at 22:25
  • 1
    Your question is bad. It lacks basic information like a minimal example containing your CMakeLists.txt file. The error message is not well formatted. How are we supposed to answer? Commented Nov 13, 2015 at 7:18

1 Answer 1

50

The answer turns out to be quite simple: cmake needs to be told to link with the DL libs, using ${CMAKE_DL_LIBS} .

So, for any target that links with a library that uses dlopen, etc, invoke:

target_link_libraries(MY_TARGET LIB1 LIB2 ... LIBN ${CMAKE_DL_LIBS}) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.