g++这个报错是怎么回事?如何解决?(涉及OpenGL)

Leon C. 2020-05-05 07:31:18
我用“g++ the_tank_war.cpp -o the_tank_war -lglfw3 -lGL -lX11 -lpthread -lXrandr -lXi”命令编译使用了glfw的c++代码时出现了下面的报错提示:

/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
x11_init.c:(.text+0x1b05): undefined reference to `XineramaQueryExtension'
x11_init.c:(.text+0x1b1d): undefined reference to `XineramaIsActive'
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `_glfwCreateCursorX11':
x11_init.c:(.text+0x23ea): undefined reference to `XcursorImageCreate'
x11_init.c:(.text+0x2507): undefined reference to `XcursorImageLoadCursor'
x11_init.c:(.text+0x2515): undefined reference to `XcursorImageDestroy'
/usr/local/lib/libglfw3.a(x11_monitor.c.o): In function `_glfwPlatformGetMonitors':
x11_monitor.c:(.text+0x682): undefined reference to `XineramaQueryScreens'
collect2: ld returned 1 exit status


代码如下:

#include<iostream>
#include<GLFW/glfw3.h>
using namespace std;

void framebuffer_size_callback(GLFWwindow* window, int width, int height);


int main()
{
glfwInit();
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 2);
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

GLFWwindow* window = glfwCreateWindow(800, 600, "fly's window", NULL, NULL);
if(window == NULL)
{
cout << "Failed to create GLFW window" << endl;
glfwTerminate();
return -1;
}

glfwMakeContextCurrent(window);

glfwSetFramebufferSizeCallback(window, framebuffer_size_callback);

while(!glfwWindowShouldClose(window))
{
glfwSwapBuffer(window);
glfwPollEvents();
}

glfwTerminate();
return 0;
}


void framebuffer_size_callback(GLFWwindow* window, int width, int height)
{
glViewport(0, 0, width, height);
}

...全文
274 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
大板牙花生 2020-05-07
  • 打赏
  • 举报
回复
undefined reference to 是未定义错误,看看是不是头文件未包含
Leon C. 2020-05-06
  • 打赏
  • 举报
回复
新增了这两个报错:

/tmp/cco8XNYv.o: In function `main':
test2.cpp:(.text+0xdd): undefined reference to `gladLoadGLLoader'
/tmp/cco8XNYv.o: In function `framebuffer_size_callback(GLFWwindow*, int, int)':
test2.cpp:(.text+0x192): undefined reference to `glad_glViewport'
/usr/local/lib/libglfw3.a(x11_init.c.o): In function `initExtensions':
Leon C. 2020-05-06
  • 打赏
  • 举报
回复
还是不行....
Simple-Soft 2020-05-05
  • 打赏
  • 举报
回复
把lGl和lglfw3交换一下顺序

24,860

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 工具平台和程序库
社区管理员
  • 工具平台和程序库社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧