Undefined Reference to 'Dlopen'

Linux c++ error: undefined reference to 'dlopen'

You have to link against libdl, add

-ldl

to your linker options

dlopen undefined reference

You have not linked with the dl library correctly. You are looking for the target_link_libraries command, using the pre-defined CMake variable CMAKE_DL_LIBS:

cmake_minimum_required(VERSION 3.14)
project(VulkanTest)

set(CMAKE_CXX_STANDARD 17)

add_executable(VulkanTest main.cpp)
target_link_libraries(VulkanTest ${CMAKE_DL_LIBS})

Undefined reference to 'dlsym' and 'dlopen'

Well, I found the answer, I needed -Wl,--no-as-needed flag before the -ldl. I had run across this flag before I asked the question, but apparently mistyped it because it hadn't worked for me.

I don't understand why the flag is needed, but the code does finish linking now.

A SO user here says that it has to do with recent (2013 as of the user's post) versions of gcc linking to --as-needed.

undefined reference to `dlopen'

Move autocheck.cpp so that it is before the libraries in your command. Libraries are only searched for things that need resolving in files that appear before them. So your command should look like this:

gcc autocheck.cpp -I/usr/lib/qt3/include -I/opt/kde3/include/  -fmessage-length=0 -O2 -Wall -D_FORTIFY_SOURCE=2 -fstack-protector -funwind-tables -fasynchronous-unwind-tables -lqt-mt -ldl -L/usr/lib/qt3/lib64 -o autocheck 


Related Topics



Leave a reply



Submit