I recently had to reinstall Linux Mint on my PC. I reinstalled all my libraries, such as GLFW and came across an error I have never seen before. Unfortunately my google-fu skills do not seem up to par for this error as I've not been able to find any fixes that work for me. Sidenote: these programs compiled fine on my old installation, and they also compile perfectly fine on my laptop that also runs Linux Mint 17.2.
This is the compile statement I using to compile:
g++ -std=c++11 main.cpp -o out -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi
This is what the terminal spits out at me:
/usr/bin/ld: //usr/local/lib/libglfw3.a(glx_context.c.o): undefined reference to symbol 'dlclose@@GLIBC_2.2.5'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libdl.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
EDIT: I have reinstalled Mint twice in order to try and fix this. It turns up everytime.
It looks like the missing symbol is from libdl
.
As an added bonus, I'm going to give you a Makefile. Remember to indent with tabs, NOT spaces, otherwise the Makefile won't work.
all: out
clean:
rm -f out *.o
.PHONY: all clean
CXX = g++
CPPFLAGS =
CXXFLAGS = -std=c++11 -Wall -Wextra -g
LIBS = -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -pthread -lXi -ldl
LDFLAGS =
out: main.o
$(CXX) $(LDFLAGS) -o $@ $^ $(LIBS)
However, it would be a lot easier if you used pkg-config
. I don't know off the top of my head the right command (I'm not on Linux now so I can't check), but it will look like this:
packages = glfw3
CPPFLAGS := $(shell pkg-config --cflags $(packages))
LIBS := $(shell pkg-config --libs $(packages))
This way you won't have to even know that you need -ldl
, because pkg-config
will figure it out for you. This is the standard way of doing things.
Try running pkg-config --libs glfw3
for yourself to see the output. If it's not installed, run sudo apt-get install pkg-config
.
I just want to simplify Dietrich Epp's answer for the less experienced programmers such as myself:
To solve this problem, link the libdl library by whatever means required by your compiler method. If using the command line (gcc): add "-ldl" to the linking commands so that the original linking command from DavidBittner above becomes:
g++ -std=c++11 main.cpp -o out -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi -ldl
Note the "-ldl" added to the end.
If you are using Cmake, add "dl" to the list of additional libs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With