有谁知道为什么 vs-code 找不到 c++ 编译器。我已经使用 vc-code 几个月没有任何问题,但是突然没有任何明确的原因它找不到编译器了!这里有人可以弄清楚是什么原因造成的吗。
任务.json
{
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command":"g++ $(pkg-config --cflags --libs opencv gl glew sdl2)",
"args": ["-g", "${workspaceFolder}/*.cpp", "-lstdc++fs", "-pthread"],
"group":{
"kind": "build",
"isDefault": true
}
}
]
}
c_cpp_properties.json
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}",
"/usr/include/c++/6.3.0",
"/usr/include/c++/6",
"/usr/include/x86_64-linux-gnu/c++/6",
"/usr/include/c++/6/backward",
"/usr/lib/gcc/x86_64-linux-gnu/6/include",
"/usr/local/include",
"/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"/usr/bin"
],
"defines": [],
"intelliSenseMode": "clang-x64",
"browse": {
"path": [
"${workspaceFolder}",
"/usr/include/c++/6.3.0",
"/usr/include/c++/6",
"/usr/include/x86_64-linux-gnu/c++/6",
"/usr/include/c++/6/backward",
"/usr/lib/gcc/x86_64-linux-gnu/6/include",
"/usr/local/include",
"/usr/lib/gcc/x86_64-linux-gnu/6/include-fixed",
"/usr/include/x86_64-linux-gnu",
"/usr/include",
"/usr/bin"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
},
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17"
}
],
"version": 3
}
输出
/bin/bash: g++ $(pkg-config --cflags --libs opencv gl glew sdl2): command not found
注意:我在vs-code的集成终端中仍然可以使用g++编译文件,但是无法被tasks.json识别!!!
最佳答案
i don't think that this could relate to this problem, cause i have been using it like this for long time with no problem. and in general during the compilation all of this parts gonna be clipped together.
您更新了您的命令,因此您的陈述不再正确。也就是说,您添加了未在 Visual Studio Code 中处理并按原样在一次命令中传递给 bash 的命令替换 $(...)
。正确的解决方案如下:
"tasks": [
{
"label": "echo",
"type": "process",
"command":"/bin/bash",
"args": [ "-c", "g++", "$(pkg-config --cflags --libs opencv gl glew sdl2)", "-g", "${workspaceFolder}/*.cpp", "-lstdc++fs", "-pthread"],
"group":{
"kind": "build",
"isDefault": true
}
}
]
或者短一点
"tasks": [
{
"label": "echo",
"type": "process",
"command":"/bin/bash",
"args": [ "-c", "g++ $(pkg-config --cflags --libs opencv gl glew sdl2) -g ${workspaceFolder}/*.cpp -lstdc++fs -pthread"],
"group":{
"kind": "build",
"isDefault": true
}
}
]
关于linux - Visual Studio Code 在 Linux 上找不到 g++ 编译器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50052729/