vscode g++链路故障:体系结构x86_64的未定义符号

vscode g++ Link failure : Undefined symbols for architecture x86_64

本文关键字:未定义 符号 x86 体系结构 g++ 链路 故障 vscode      更新时间:2023-10-16

基本信息:

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

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

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

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

我做过的事:

  1. 可以找到头文件。

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

  3. 尝试添加"g++-框架XXXXX",但不起作用
  4. 尝试添加"g++-lglfw3",但不起作用
  5. 添加"g++-L或I/usr/lib或/usr/local/lib或/usr/local/include",但不起作用

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

将greed.c添加到构建阶段->编译源