【问题标题】:freeglut libraries not linking properly. Any way to point the linker to their proper location?freeglut 库没有正确链接。有什么方法可以将链接器指向正确的位置?
【发布时间】:2021-06-01 16:19:25
【问题描述】:

我只是想使用 freeglut 显示一个窗口。我使用 homebrew 安装 xquartz、freeglut 和 glfw3,因为这些是互联网告诉我安装的东西。然后我开始构建一个只显示一个窗口的基本应用程序,但是当我尝试编译时出现以下错误:

Undefined symbols for architecture x86_64:
  "_glutCreateWindow", referenced from:
      _main in project01-a62b50.o
  "_glutInit", referenced from:
      _main in project01-a62b50.o
  "_glutMainLoop", referenced from:
      _main in project01-a62b50.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

上面提到的错误函数都是freeglut库支持的。在过去的 3 周里,我一直在谷歌上搜索。我正在使用 vs 代码并使用命令行进行编译。以下是我的不完整代码。

#include <GL/freeglut.h>
#include <GL/gl.h>
#include <GLFW/glfw3.h>

int main(int argc, char** argv)
{
    //Initializations
    glutInit(&argc, argv);
    glutCreateWindow("Hello World"); 


    //Call main loo=
    glutMainLoop(); 
    return 0; 
}

我已经尝试用以下代码编译和链接程序。

g++ project01.cpp -o project01 -L /usr/local/lib -I /usr/local/include
g++ project01.cpp -o project01 -L /usr/local/opt -I /usr/local/include
g++ project01.cpp -o project01 -lx11 -lxi -lxrandr -lxxf86vm -I /usr/local/include
g++ -o project01 project01.cpp 
g++ project01.cpp

我并不真正了解编译或链接过程,但是,据我所知,我收到此错误是因为链接器找不到合适的库文件。我不知道如何解决这个问题。如果有人能给我任何见解,那将是巨大的。先谢谢大家了!!

最好的

【问题讨论】:

    标签: c++ macos linker homebrew freeglut


    【解决方案1】:

    原来我没有链接必要的库。我是 c++ 和 openGL 开发的新手,所以这就是我最终为与我处于同一位置的人编译代码的方式。

    g++ project01.cpp -o project01 -lglut -lgl -I /usr/local/include
    

    希望对您有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-03-21
      • 1970-01-01
      • 2013-11-06
      • 2016-12-29
      • 1970-01-01
      • 2021-10-31
      • 2016-09-06
      • 1970-01-01
      相关资源
      最近更新 更多