[英]Intellisense does not show function descriptions in Visual Studio Code for C++ using the clang++ compiler on macOS
[英]How can I include .dylib files in ".json" configuration files? - VS Code on Mac iOS - Clang++ compiler - Language: c++
我在谷歌上找了 2 天沒有成功地找到一個明確的段落來描述如何包含動態庫(Mac iOS 上擴展名為.dylib
的文件)以便在有人設置任務時由clang++
編譯。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
頭文件中編譯:
// 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:錯誤:linker 命令失敗,退出代碼為 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
}
}
]
}
向所有讀者致以最美好的問候。
看來您確實需要將庫傳遞到 clang++ 的 arguments 中。
嘗試使用 -l 標志執行此操作,指向目標庫。
添加"-l /usr/local/Cellar/glfw/3.3.3/lib/libglfw.3.3.dylib"
和
"-l /usr/local/Cellar/glew/2.2.0_1/lib/libGLEW.2.2.0.dylib"
到 args 字符串列表。
這個特定問題的解決方案是在task.json
中添加下一個命令 arguments:
任務.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
}
}
]
}
正如大家所看到的,只需將文件的完整路徑寫為附加參數,編譯器就會接受
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.