glfw3 error: DSO Missing from command line

邮差的信 提交于 2019-11-30 09:22:25

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 "-ldl" to the list of additional libs.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!