Undefined reference to 'dlsym' and 'dlopen'

I am compiling with arm-linux-gnueabi-g ++ version 4.7.3.

I have arm-linux-gnueabi libraries installed in the location:

/ usr / arm-linux-gnueabi / lib, it contains libdl.a, libdl.so, libdl.so.2, and libdl-2.19.so.

Links libdl.so to libdl.so.2, which references libdl-2.19.so.

I am trying to link to the dl library (see below command), but always get undefined reference errors.

arm-linux-gnueabi-g++ -I. -I../ -I../Comms/Linux -Wall -DLINUX -fpic -o ../../work/MyProgram main.o -L../../work -L/usr/arm-linux-gnueabi/lib -lComms -lConsole -lUtilities -ldl ../../work/libUtilities.so: undefined reference to `dlsym' ../../work/libUtilities.so: undefined reference to `dlopen' collect2: error: ld returned 1 exit status 

If I compile with g ++ 4.8.2 using the following commend, then my program compiles, links, and performs fine.

 g++ -I. -I../ -I../Comms/Linux -Wall -DLINUX -fpic -o ../../work/MyProgram main.o -L../../work -lComms -lConsole -lUtilities -ldl 

Obviously, he cannot find the libdl.so library; I thought that adding the path to the location of the corresponding library using the -L flag would fix the problem, but it is not.

What am I missing using the ARM compiler command?

+6
source share
1 answer

Well, I found the answer, I need the -Wl,--no-as-needed flag -Wl,--no-as-needed before -ldl . I ran into this flag before I asked a question, but apparently I was mistaken because it did not work for me.

I don’t understand why a flag is needed, but the code completes the binding.

The SO user here says that he is connected with the latest versions of gcc-related gas-related, with the latest (as is the case with the user). p>

+10
source

Source: https://habr.com/ru/post/980045/


All Articles