glfw3编译未定义的引用 [英] glfw3 compiling undefined references

查看:443
本文介绍了glfw3编译未定义的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个编译我的程序使用glfw3库的问题。

I have a problem with compiling my program which uses glfw3 library.

我得到未定义的引用的错误列表当尝试编译与make但我的类。

stdout:

I'm getting list of errors of undefined references when trying to compile with make but my classes are compiled into .o files, only final executable file is not created.

stdout:

stderr:

stderr:

这是我的makefile:

/usr/local/lib/libglfw3.a(context.c.o): In function `parseGLVersion': context.c:(.text+0x53): undefined reference to `glGetString' /usr/local/lib/libglfw3.a(context.c.o): In function `_glfwRefreshContextAttribs': context.c:(.text+0x907): undefined reference to `glGetIntegerv' context.c:(.text+0x98a): undefined reference to `glGetIntegerv' context.c:(.text+0x9df): undefined reference to `glGetIntegerv' context.c:(.text+0xa32): undefined reference to `glGetIntegerv' /usr/local/lib/libglfw3.a(context.c.o): In function `glfwExtensionSupported': context.c:(.text+0xd59): undefined reference to `glGetString' context.c:(.text+0xd93): undefined reference to `glGetIntegerv' /usr/local/lib/libglfw3.a(window.c.o): In function `glfwCreateWindow': window.c:(.text+0x6f8): undefined reference to `glClear' /usr/local/lib/libglfw3.a(x11_time.c.o): In function `getRawTime': x11_time.c:(.text+0x20): undefined reference to `clock_gettime' /usr/local/lib/libglfw3.a(x11_time.c.o): In function `_glfwInitTimer': x11_time.c:(.text+0x72): undefined reference to `clock_gettime' /usr/local/lib/libglfw3.a(glx_context.c.o): In function `getFBConfigAttrib': glx_context.c:(.text+0x51): undefined reference to `glXGetFBConfigAttrib' /usr/local/lib/libglfw3.a(glx_context.c.o): In function `chooseFBConfig': glx_context.c:(.text+0x7e): undefined reference to `glXGetClientString' glx_context.c:(.text+0x104): undefined reference to `glXGetFBConfigs' /usr/local/lib/libglfw3.a(glx_context.c.o): In function `createLegacyContext': glx_context.c:(.text+0x43f): undefined reference to `glXCreateNewContext' /usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwInitContextAPI': glx_context.c:(.text+0x48f): undefined reference to `glXQueryExtension' glx_context.c:(.text+0x4ca): undefined reference to `glXQueryVersion' /usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwCreateContext': glx_context.c:(.text+0x791): undefined reference to `glXGetVisualFromFBConfig' /usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwDestroyContext': glx_context.c:(.text+0xd09): undefined reference to `glXDestroyContext' /usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformMakeContextCurrent': glx_context.c:(.text+0xd55): undefined reference to `glXMakeCurrent' glx_context.c:(.text+0xd70): undefined reference to `glXMakeCurrent' /usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformSwapBuffers': glx_context.c:(.text+0xdc2): undefined reference to `glXSwapBuffers' /usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformExtensionSupported': glx_context.c:(.text+0xe69): undefined reference to `glXQueryExtensionsString' /usr/local/lib/libglfw3.a(glx_context.c.o): In function `_glfwPlatformGetProcAddress': glx_context.c:(.text+0xeb1): undefined reference to `glXGetProcAddressARB' collect2: ld returned 1 exit status make: *** [ecl] Error 1

this is my makefile:



CXX = g++ CXXFLAGS = -Wall -g LIBS = -lGL -lGLU -lglfw3 -lX11 -lXxf86vm -lXrandr -lpthread -lXi DEPENDENCIES = main.o error.o sWindow.o # **************************************************** # Targets needed to bring the executable up to date ecl: $(DEPENDENCIES) $(CXX) $(CXXFLAGS) -o ecl $(DEPENDENCIES) $(LIBS) main.o: main.cpp $(CXX) $(CXXFLAGS) -c main.cpp $(LIBS) error.o: error.cpp $(CXX) $(CXXFLAGS) -c error.cpp $(LIBS) sWindow.o: sWindow.cpp $(CXX) $(CXXFLAGS) -c sWindow.cpp $(LIBS) clean: rm -f *.o main echo "Clean done"

推荐答案

按照以下顺序执行:

-lglfw3 -lGLU -lGL

而不是这一个:

-lGL -lGLU -lglfw3

GCC对在链接阶段指定库的顺序非常敏感。例如,如果 libA.a 依赖于 libB.a ,那么你必须在下面调用linker方式:

GCC is very sensitive to the order in which you specify libraries during the linking stage. For example, if libA.a depends on libB.a, then you'd have to invoke linker in the following way:

gcc ... -lA -lB ...

在你的情况下, libglfw3.a 显然取决于 libGL.a ,因此您得到的错误。

In your case, libglfw3.a obviously depends on libGL.a, hence the errors you are getting.

这篇关于glfw3编译未定义的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆