在 Ubuntu(g++) 上编译 OpenGL/glfw/glew 的未定义引用
Undefined References Compiling OpenGL/glfw/glew on Ubuntu(g++)
我正在关注 this tutorial。我 cmake'd
和 make/make install'd
glfw
和 glew
完美(据我所知)。但是,当我尝试编译示例代码时...
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
return 0;
}
...使用他的链接器标志...
-lGLEW -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi
...我收到以下错误:
/usr/bin/ld: /usr/local/lib/libglfw3.a(x11_init.c.o): undefined reference to symbol 'XF86VidModeQueryExtension'
/usr/lib/x86_64-linux-gnu/libXxf86vm.so.1: error adding symbols: DSO missing from command line
我 Google 出错了,有人建议添加 -lXxf86vm
。它消除了最初的错误,但增加了更多的错误:
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x1b93): undefined reference to `XineramaQueryExtension'
x11_init.c:(.text+0x1bad): undefined reference to `XineramaIsActive'
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `_glfwCreateCursor':
x11_init.c:(.text+0x22ee): undefined reference to `XcursorImageCreate'
x11_init.c:(.text+0x23c5): undefined reference to `XcursorImageLoadCursor'
x11_init.c:(.text+0x23d5): undefined reference to `XcursorImageDestroy'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors':
x11_monitor.c:(.text+0x743): undefined reference to `XineramaQueryScreens'
如何确定我需要哪些标志?如果重要的话,这就是我的 makefile 的结构:
CC = g++
COMPILER_FLAGS = -std=c++11
FILES = *.cpp
LINKER_FLAGS = -lGLEW -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi -lXxf86vm
OBJS = *.o
LINUX_BIN = HelloWindow
#Compile(output into error.txt if there is an error), link, then run
linux:
$(CC) $(COMPILER_FLAGS) -c $(FILES) 2> "errors.txt"
$(CC) $(COMPILER_FLAGS) $(OBJS) -o $(LINUX_BIN) $(LINKER_FLAGS)
./$(LINUX_BIN)
谢谢!
Derhass 是正确的。以下是我使用的标志:
-lGLEW -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread
我正在关注 this tutorial。我 cmake'd
和 make/make install'd
glfw
和 glew
完美(据我所知)。但是,当我尝试编译示例代码时...
#define GLEW_STATIC
#include <GL/glew.h>
#include <GLFW/glfw3.h>
int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
glfwWindowHint(GLFW_RESIZABLE, GL_FALSE);
return 0;
}
...使用他的链接器标志...
-lGLEW -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi
...我收到以下错误:
/usr/bin/ld: /usr/local/lib/libglfw3.a(x11_init.c.o): undefined reference to symbol 'XF86VidModeQueryExtension'
/usr/lib/x86_64-linux-gnu/libXxf86vm.so.1: error adding symbols: DSO missing from command line
我 Google 出错了,有人建议添加 -lXxf86vm
。它消除了最初的错误,但增加了更多的错误:
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x1b93): undefined reference to `XineramaQueryExtension'
x11_init.c:(.text+0x1bad): undefined reference to `XineramaIsActive'
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `_glfwCreateCursor':
x11_init.c:(.text+0x22ee): undefined reference to `XcursorImageCreate'
x11_init.c:(.text+0x23c5): undefined reference to `XcursorImageLoadCursor'
x11_init.c:(.text+0x23d5): undefined reference to `XcursorImageDestroy'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors':
x11_monitor.c:(.text+0x743): undefined reference to `XineramaQueryScreens'
如何确定我需要哪些标志?如果重要的话,这就是我的 makefile 的结构:
CC = g++
COMPILER_FLAGS = -std=c++11
FILES = *.cpp
LINKER_FLAGS = -lGLEW -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi -lXxf86vm
OBJS = *.o
LINUX_BIN = HelloWindow
#Compile(output into error.txt if there is an error), link, then run
linux:
$(CC) $(COMPILER_FLAGS) -c $(FILES) 2> "errors.txt"
$(CC) $(COMPILER_FLAGS) $(OBJS) -o $(LINUX_BIN) $(LINKER_FLAGS)
./$(LINUX_BIN)
谢谢!
Derhass 是正确的。以下是我使用的标志:
-lGLEW -lglfw3 -lGL -lX11 -lXi -lXrandr -lXxf86vm -lXinerama -lXcursor -lrt -lm -pthread