c++ - 如何在“.json”配置文件中包含 .dylib 文件?- Mac iOS 上的 VS Code - Clang++ 编译器 - 语言:c++
问题描述
我在谷歌上找了 2 天没有成功地找到一个清晰的段落来描述如何包含动态库(.dylib
Mac iOS 上具有扩展名的文件)以便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
;
不得不提的是,我成功地按照以下代码片段在OpenGL main.cpp文件和头文件中进行了clang++
编译:glew.h
glfw3.h
// 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
}
}
]
}
向所有读者致以最美好的问候。
解决方案
这个特定问题的解决方案是添加task.json
下一个命令参数:
任务.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
}
}
]
}
正如大家所看到的,只需将文件的完整路径写为附加参数,编译器就会接受
推荐阅读
- java - 使用 Bouncy Castle 的三重 DES Java 实现返回意外结果
- python-3.x - 为什么在 Python 3 中会出现重复的命令
- kubernetes - Apache Ignite:将 1000 条警告“无法在超时内执行握手”添加到日志中
- javascript - 如何添加传递的参数时区并获得 hh:mm 的 zz 格式?
- r - R中的Webscraping“open.connection(x,“rb”)中的错误:HTTP错误403。”
- postgresql - 我无法完成请求,我该怎么办?
- html - 为什么即使显示:inline-block,背景颜色也不会捕捉?
- c# - 访问类和类中的数组
- xml - xml定义位置上的Powershell Append()属性
- java - 将给定的字符串答案与实际时间进行比较?