【发布时间】:2021-08-02 20:58:54
【问题描述】:
我在谷歌上找了 2 天没有成功地找到一个明确的段落来描述如何包含动态库(Mac iOS 上扩展名为 .dylib 的文件)以便在有人设置时由 clang++ 编译 task.json 和/或 c_cpp_properties.json 文件 - (在按下 F5 以启动任务并执行源代码之前)
我特别想包括接下来的两个 .dylib 文件:
-
/usr/local/Cellar/glfw/3.3.3/lib/libglfw.3.3.dylib; -
/usr/local/Cellar/glew/2.2.0_1/lib/libGLEW.2.2.0.dylib;
不得不提的是,我成功地将clang++ 编译到OpenGL main.cpp 文件中,glew.h 和glfw3.h 标头都按照以下 sn-p:
// GLEW
#define GLEW_STATIC
#include <GL/glew.h>
// GLFW
#include <GLFW/glfw3.h>
...
此任务已完成写入下一个c_cpp_properties.json 文件:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"${workspaceFolder}/include"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang++",
"cStandard": "gnu17",
"cppStandard": "gnu++14",
"intelliSenseMode": "macos-gcc-x64"
}
],
"version": 4
}
魔法是由"macFrameworkPath" 指令完成的。
但还不够。
clang++ 编译时我仍然有这个错误:
clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)。
而这 - 正如我在谷歌搜索解决方案后所理解的那样 - 发生是因为有必要包含我之前提到的这两个动态库。
但正如我一开始所说,我没有找到如何去做。
也许有人可以提出一个明确而适当的解决方案。
我最好的猜测是在task.json 脚本中添加一个新参数,顺便说一下:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "clang++ build active file",
"command": "/usr/bin/clang++",
"args": [
"-std=c++17",
"-stdlib=libc++",
"-g",
"${file}",
"-I/Users/Armonicus/MyProjects/C++VSCodeProjects/projects/helloworld01/include",
"-o",
"${fileDirname}/src/${fileBasenameNoExtension}",
"-Wno-deprecated",
"-Wno-pragma-once-outside-header"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
向所有读者致以最诚挚的问候。
【问题讨论】:
标签: c++ macos vscode-settings clang++ dylib