C++:ubuntu未定义引用的glfw3

Kur*_*uro 3 c++ opengl g++ glfw ubuntu-13.10

我正在尝试编译教程中的程序.

#include <GLFW/glfw3.h>
#include <stdlib.h>
#include <stdio.h>

static void error_callback(int error, const char* description)
{
 fputs(description, stderr);
}
static void key_callback(GLFWwindow* window, int key, int scancode, int action, int mods)
{
 if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
 glfwSetWindowShouldClose(window, GL_TRUE);
}
int main(void)
{
 GLFWwindow* window;
 glfwSetErrorCallback(error_callback);
 if (!glfwInit())
 exit(EXIT_FAILURE);
 window = glfwCreateWindow(640, 480, "Simple example", NULL, NULL); 
 if (!window)
 {
  glfwTerminate();
  exit(EXIT_FAILURE);
 }
 glfwMakeContextCurrent(window);
 glfwSetKeyCallback(window, key_callback);
 while (!glfwWindowShouldClose(window))
 {
  float ratio;
  int width, height;
  glfwGetFramebufferSize(window, &width, &height);
  ratio = width / (float) height;
  glViewport(0, 0, width, height);
  glClear(GL_COLOR_BUFFER_BIT);
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  glOrtho(-ratio, ratio, -1.f, 1.f, 1.f, -1.f);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glRotatef((float) glfwGetTime() * 50.f, 0.f, 0.f, 1.f);
  glBegin(GL_TRIANGLES);
  glColor3f(1.f, 0.f, 0.f);
  glVertex3f(-0.6f, -0.4f, 0.f);
  glColor3f(0.f, 1.f, 0.f);
  glVertex3f(0.6f, -0.4f, 0.f);
  glColor3f(0.f, 0.f, 1.f);
  glVertex3f(0.f, 0.6f, 0.f);
  glEnd();
  glfwSwapBuffers(window);
  glfwPollEvents();
 }
 glfwDestroyWindow(window);
 glfwTerminate();
 exit(EXIT_SUCCESS);
 }
Run Code Online (Sandbox Code Playgroud)

我尝试编译时得到的结果:

/usr/local/lib/libglfw3.a(x11_window.c.o): In function `_glfwPlatformCreateCursor':
x11_window.c:(.text+0x2d91): undefined reference to `XcursorImageCreate' 
x11_window.c:(.text+0x2e61): undefined reference to `XcursorImageLoadCursor'
x11_window.c:(.text+0x2e75): undefined reference to `XcursorImageDestroy'
Run Code Online (Sandbox Code Playgroud)

我用这个命令

g++ glfw.o -lglfw3 -lGL -lGLU -lX11 -lXxf86vm -lXrandr -lpthread -lXi -lm -lalleg
Run Code Online (Sandbox Code Playgroud)

在Ubuntu 13.10上运行

我到处寻找,安装了box2d,glfw,glfw3,allegro和一些libs - 原因是我经历了远程提到glfw和未定义引用的每一个讨论,并且由于五个小时的僵局导致我的挫败感,安装了任何库被提到了.结果保持不变.我不知道从哪里开始.是什么原因导致这个问题?谢谢.

Kur*_*uro 11

直到先生.AndonM.Coleman发布了这个问题的答案(他在评论中做了),问题是缺失了-lXcursor