Undefined Reference to Symbol 'Dlsym@@Glibc_2.4'

undefined reference to symbol 'dlsym@@GLIBC_2.4'

In general, the man page for the symbol you can't find tells you what libraries you need to link in. In your case:

http://linux.die.net/man/3/dlsym

Note the line:

Link with -ldl.

Cmake undefined reference to symbol 'dlsym@@GLIBC_2.2.5 even though I link with -ldl

Would you inspect carefully the actual command line used for linking, you will find that after libsmoltcp_cpp_interface_rust.a, which has missed symbol, there is no -ldl parameter.

It seems that in your case smoltcp_cpp is an IMPORTED library target, which has libsmoltcp_cpp_interface_rust.a as a link dependency (not as IMPORTED_LOCATION property or so).

While CMake preserves order of the libraries, linked into a single binary (an or another library), order between dependencies of these libraries is not defined.

You need to add -ldl as a link dependency for the smoltcp_cpp target itself:

target_link_libraries(smoltcp_cpp INTERFACE -ldl)

However, this will work only if libsmoltcp_cpp_interface_rust.a is a direct link dependency for smoltcp_cpp target, that is specified as

target_link_libraries(smoltcp_cpp INTERFACE libsmoltcp_cpp_interface_rust.a)

In case of indirect dependencies, like

target_link_libraries(smoltcp_cpp INTERFACE <intermediate-target>)
target_link_libraries(<intermediate-target> INTERFACE libsmoltcp_cpp_interface_rust.a)

you need to add -ldl as a dependency for that <intermediate-target>.

Ideally, every IMPORTED target should be self-contained, so you may safely link with that target without knowing its internals.

undefined reference to symbol 'dlsym@@GLIBC_2.2.5'

I found out the "-ldl" link option was ignored because it was placed too early in the final c++ link command during make. So if you want to use external .so file and need to use libdl.so, you should configure qemu like this. (under qemu-5.1.0/build directory)

../configure --target-list=aarch64-softmmu --enable-debug --enable-gtk
--extra-ldflags="-Wl,--no-as-needed,-ldl"

The -Wl,--no-as-needed,-ldl part was added. (the others are for my needs). -as-needed is the default and it lists the needed library in the elf file. I tested it with just -ldl but it didn't work, hence the final command.

How to fix undefined reference to symbol 'dlclose@@GLIBC_2.2.5' from glad.c

The linker is complaining about not finding dlclose.
You can add libdl with CMAKE_DL_LIBS.
Addtionally, make use of the modern linking with targets instead of strings.

Change your CMakeLists.txt to:

cmake_minimum_required(VERSION 3.14)
project(openglTuto)


add_executable(gltuto src/main.c src/glad.c)

find_package(glfw3 3.3 REQUIRED)
find_package(OpenGL REQUIRED)

target_include_directories(gltuto PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/include>
$<INSTALL_INTERFACE:include>)
target_link_libraries(gltuto PUBLIC glfw OpenGL::GL ${CMAKE_DL_LIBS})

Look up Generator Expressions to understand BUILD_INTERFACE and INSTALL_INTERFACE.

Undefined reference to 'dlsym'

I have found the solution; setting the -Wl,--no-as-needed before -ldl. The new compile command is:

gcc main.cpp -lsqlapi -lstdc++ -Wl,--no-as-needed -ldl

Apparently it has something to do with recent versions of gcc/ld linking with --as-needed by default.

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.

linker cannot find dlsym

I suggest to use the LIBS variable for this rather than the QMAKE_LFLAGS as follows:

LIBS += -ldl -fPIC


Related Topics



Leave a reply



Submit