1

I have code that loads library dynamically. I got errors like below after run make.

aaa.cpp:(.text+0x4ea): undefined reference to `dlopen'
aaa.cpp:(.text+0x50b): undefined reference to `dlerror'
aaa.cpp:(.text+0x54e): undefined reference to `dlsym'
aaa.cpp:(.text+0x560): undefined reference to `dlerror'
aaa.cpp:(.text+0x56f): undefined reference to `dlerror'
aaa.cpp:(.text+0x595): undefined reference to `dlclose'
aaa.cpp:(.text+0x5b8): undefined reference to `dlsym'
aaa.cpp:(.text+0x5ca): undefined reference to `dlerror'
aaa.cpp:(.text+0x5d9): undefined reference to `dlerror'
...

That makes me think dl is missing. What is the best way to install dl in Ubuntu?

UPD

libc6-dev is already installed on my system

$ sudo aptitude install libc6-dev
libc6-dev is already installed at the requested version (2.23-0ubuntu9)
libc6-dev is already installed at the requested version (2.23-0ubuntu9)
No packages will be installed, upgraded, or removed.

makefile:

# Options for development
COMPILER = g++
#CFLAGS = -c -Wall -ansi
CFLAGS = -fPIC -c
# Options for release
#CFLAGS = -c -Wall -O

client:
        $(COMPILER) $(CFLAGS) c1.cpp -o c1.o
        $(COMPILER) -ldl c1.o -o aa

clean:
        rm *.o
        rm aa
vico
  • 4,447
  • 20
  • 55
  • 87
  • did you see this: https://stackoverflow.com/questions/956640/linux-c-error-undefined-reference-to-dlopen or this https://askubuntu.com/questions/454443/how-do-i-deal-with-undefined-reference-to-dlopen-errors-while-compiling-and-us – pLumo Dec 19 '17 at 13:37
  • 1
    I doubt `libdl` is missing from your system (it's part of the `libc6-dev` package). More likely, `-ldl` is missing from (or in the wrong place on) your linker command line. – steeldriver Dec 19 '17 at 13:38
  • libc6-dev is already installed, and makefile just adds -ldl . See UPD. How to know where is my dl placed? – vico Dec 19 '17 at 13:49
  • 2
    Try `$(COMPILER) -o aa c1.o -ldl ` - for reference, see (for example) [Why does the order in which libraries are linked sometimes cause errors in GCC?](https://stackoverflow.com/questions/45135/why-does-the-order-in-which-libraries-are-linked-sometimes-cause-errors-in-gcc) – steeldriver Dec 19 '17 at 14:19

0 Answers0