C++ 如何将.dylib文件包含在";中;。json";配置文件?-Mac iOS上的VS代码-铿锵++;编译器-语言:c++;
我在google上搜索了两天,没有找到一个清晰的段落来描述如何包含动态库(Mac iOS上扩展名为C++ 如何将.dylib文件包含在";中;。json";配置文件?-Mac iOS上的VS代码-铿锵++;编译器-语言:c++;,c++,macos,vscode-settings,clang++,dylib,C++,Macos,Vscode Settings,Clang++,Dylib,我在google上搜索了两天,没有找到一个清晰的段落来描述如何包含动态库(Mac iOS上扩展名为.dylib的文件),以便在有人设置任务.json和/或c_cpp_properties.json文件时由clang++编译,但没有成功(在按下F5以启动任务并执行源代码之前) 我特别想包括下面两个.dylib文件: /usr/local/ceral/glfw/3.3.3/lib/libglfw.3.3.dylib /usr/local/ceral/glew/2.2.0_1/lib/libGLEW.
.dylib
的文件),以便在有人设置任务.json和/或c_cpp_properties.json文件时由clang++
编译,但没有成功(在按下F5
以启动任务并执行源代码之前)
我特别想包括下面两个.dylib文件:
/usr/local/ceral/glfw/3.3.3/lib/libglfw.3.3.dylib
/usr/local/ceral/glew/2.2.0_1/lib/libGLEW.2.2.0.dylib
clang++
在OpenGL main.cpp文件中编译了glew.h
和glfw3.h
标题,如下所示:
// GLEW
#define GLEW_STATIC
#include <GL/glew.h>
// GLFW
#include <GLFW/glfw3.h>
...
其中魔法是通过“macFrameworkPath”
指令完成的
但这还不够。
当clang++
编译时,我仍然存在此错误:
clang:error:linker命令失败,退出代码为1(使用-v查看调用)
正如我在谷歌搜索解决方案后所理解的那样,之所以会出现这种情况,是因为必须包含我前面提到的两个动态库。
但正如我一开始说的,我不知道该怎么做。
也许有人能想出一个明确而适当的解决办法。
我的最佳猜测是在task.json
script中添加一个新参数,顺便说一下,它如下所示:
{
// 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
}
}
]
}
向所有读者致以最良好的祝愿。看来您确实需要将LIB传递到clang++的参数中 尝试使用指向目标库的-l标志执行此操作 加
“-l/usr/local/ceral/glfw/3.3.3/lib/libglfw.3.3.dylib”
及
“-l/usr/local/ceral/glew/2.2.0_1/lib/libGLEW.2.2.0.dylib”
到字符串的args列表。此特定问题的解决方案是添加task.json
下一个命令参数:
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",
"/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",
"-o",
"${fileDirname}/src/${fileBasenameNoExtension}",
"-Wno-deprecated",
"-Wno-pragma-once-outside-header"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
正如大家所看到的,编译器只需将文件的完整路径作为附加参数写入即可接受谢谢!似乎
clang++
无法访问/usr/local文件夹,或者至少这是我所怀疑的。错误是:ld:library not found for-l/usr/local/cillar/glfw/3.3.3/lib/glfw.3.3.dylib clang:error:linker命令失败,退出代码为1(使用-v查看调用)
。我应该在task.json中包含sudo comand或类似的东西吗?
{
// 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",
"/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",
"-o",
"${fileDirname}/src/${fileBasenameNoExtension}",
"-Wno-deprecated",
"-Wno-pragma-once-outside-header"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": ["$gcc"],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}