c++ - 使用 VSCode MACOS 构建时 GLFW 链接器命令失败(退出代码 1)
问题描述
在使用 Visual Studio Code 的 C++/C 扩展启动并运行后,我尝试使用 GLFW 创建一个窗口。我已经下载了GLFW,我的项目的文件结构如下:
引擎(工作区文件夹)-> 源文件-> test.cpp
引擎(工作区文件夹)-> 依赖项-> GLFW 库
这是我生成窗口的 C++ 代码:
#include <iostream>
#include <GLFW/glfw3.h>
using namespace std;
int main() {
GLFWwindow* window = glfwCreateWindow(640, 480, "My Title", NULL, NULL);
if (!window)
{
// Window or OpenGL context creation failed
}
}
这是我使用 clang++ 构建的 tasks.json 配置:
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I/Users/mynamew/Desktop/Engine/Dependencies/glfw-3.3.4.bin.MACOS/include"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
},
这是我的 c_cpp_properties.json 配置:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"/Users/myname/Desktop/Engine/Dependencies/glfw-3.3.4.bin.MACOS/include"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang++",
"cStandard": "c11",
"cppStandard": "c++98",
"intelliSenseMode": "macos-clang-x64"
}
],
"version": 4
}
当我尝试构建项目时,我收到以下错误消息:
Undefined symbols for architecture x86_64:
"_glfwCreateWindow", referenced from:
_main in test-9301bf.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1
我的 Mac 架构和 GLFW 之间是否存在导致链接问题的兼容性问题?如果是这样,有什么解决办法还是我运气不好?任何帮助将不胜感激。
另外,一个元问题,但链接器错误是否表明编译成功但只有链接失败?据我了解,链接器是在编译之后出现的。
解决方案
推荐阅读
- reactjs - 如何在标签导航的标题标题中添加标题?
- mongodb - 在aws ec2容器上部署mongodb并在aws ECS集群中使用实例名访问mongodb
- css - 制作一个在随机位置显示或隐藏多个图像的按钮
- node.js - 为什么我会遇到这个 NodeJS 安装问题?
- sql - 没有 RESEED 的 MSSQL 身份插入
- rust - 错误:不能借用......作为不可变的,因为它也被借用为可变的
- django - Docker Compose 到 Cloud Run
- csv - TypeError [ERR_INVALID_Callback] 调用必须是函数......当尝试从 CSV 文件在 Postman 中运行集合时
- excel - Excel - 允许在工作表仍打开时从 MATLAB 进行编辑
- web-scraping - 使用 Google Sheet Formula IMPORTXML 从网页上的表格中提取超链接,并在图像在单独的列中时进行标记