【问题标题】:vscode g++ Link failure : Undefined symbols for architecture x86_64vscode g ++链接失败:架构x86_64的未定义符号
【发布时间】:2018-11-03 13:12:29
【问题描述】:

基本信息:

  1. 系统:macOS High Sierra(10.13.6)
  2. 编辑器:vs代码(最新版)
  3. 编译器:g++ (Xcode)
  4. 目标:部署GLFW + GLAD

问题描述:
最近,我正在学习做一些计算机图形相关的工作。一切都很顺利。但是,当我创建一个窗口来测试 env.Link 时发生错误:

Undefined symbols for architecture x86_64:
"_gladLoadGLLoader", referenced from:
  _main in main-5c211c.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The terminal process terminated with exit code: 1

似乎我没有链接一些第三方文件。 我 在 glfw3.h 中使用函数时,通过在 g++ 中添加“-lglfw”参数解决了完全相同的问题。
但是当遇到glad相关函数:gladLoadGLLoader时,我不知道该怎么做。

我做过的事情:

  1. 可以找到头文件。

    #include glad/glad.h  
    #include GLFW/glfw3.h  
    
  2. 已将文件“glad.c”放入工作区。

  3. 尝试添加“g++ -framework XXXXX”,但不起作用。
  4. 尝试添加“g++ -lglfw3”,但不起作用。
  5. 添加“g++ -L or I /usr/lib or /usr/local/lib or /usr/local/include”,但是不起作用。

【问题讨论】:

  • 您可能需要明确引用具有gladLoadGLLoader 的.lib 文件,而不仅仅是指定它的路径。
  • 感谢您的建议! gladLoadGLLoaderglad.c 文件中定义。老实说,我不知道在哪里可以找到具有该功能的 .lib 文件。很高兴我下载的只包含两个.h文件glad.hkhrplatform.h和一个src文件glad.c,我想我把它们放在正确的位置:/usr/local/include中的头文件和glad.c中的头文件工作区。 glad generator address

标签: c++ opengl visual-studio-code g++ glfw


【解决方案1】:

只需通过将“glad.c”添加到args 来告诉g++ 编译glad.c。我以为glad.c会默认编译。虽然不清楚发生了什么,但问题还是解决了。

【讨论】:

    【解决方案2】:

    将glad.c 添加到Build Phases->Compile Sources

    【讨论】:

    • "Build Phases->Compile Sources" 是 Xcode 的一部分。 OP 正在使用 Visual Studio Code。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多