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
So, if anyone can tell me why I'm getting this/or how to fix it that would be absolutely amazing! Thanks ahead of time for any help.
EDIT: I have reinstalled Mint twice in order to try and fix this. It turns up everytime.
EDIT 2: I've been fiddling around and still have yet to find an issue.
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
.