VS Code "command":"make"与终端窗口中的命令行"make"不同

VS Code "command": "make" differs from command line `make` in terminal window

本文关键字:make 命令行 不同 窗口 Code command VS 终端      更新时间:2023-10-16

我前段时间安装了Linux版的VS Code,在工作区中打开了一个C++项目,创建了tasks.json——总的来说,我做的一切都是按照谷歌的。

当我在终端窗口中运行make命令时,一切都很好。但当我在VS Code中执行同样的操作(Ctrl+Shift+B(时,我会得到一个错误。

在命令libtool: link: c++ -fPIC -DPIC -shared -nostdlib /usr/bin/../lib/gcc/x86_64-linux-gnu/7.3.0/../../../x86_64-linux-gnu/crti.o ....之后,处理我的Makefile终止

带有消息c++: error: /usr/bin/../lib/gcc/x86_64-linux-gnu/7.3.0/../../../x86_64-linux-gnu/crti.o: No such file or directory

当然,路径是正确的(当我在终端窗口中使用命令行make时,路径是好的(。

tasks.json的内容很琐碎(与microsoft.com相同(:

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "ClanLib",
"type": "shell",
"command": "make",
// start the build without prompting for task selection, use "group": "build" otherwise
"group": {
"kind": "build",
"isDefault": true
},
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared"
},
// arg passing example: in this case is executed make QUIET=0
"args": ["QUIET=0"],
// Use the standard less compilation problem matcher.
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["absolute"],
"pattern": {
"regexp": "^(.*):(\d+):(\d+):\s+(warning|error):\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
}
}
]
}

我不能发布Makefile,它由从https://github.com/sphair/ClanLib...

请帮助设置Visual Studio代码(Linux Mint(。

看起来您尝试在一个目录中手动构建makefile,并从另一个目录构建vscode。如果是这种情况,您可以使用cwd选项-doc:告诉您的任务从特定目录运行

{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "ClanLib",
"type": "shell",
"command": "make",
"options": {
"cwd": "${workspaceRoot}/<DIR_WITH_MAKEFILE>"
}
...
}]}

我好像感觉到了什么。在VSCode内部的终端窗口中,我看到

sh-4.4$ help
GNU bash, версия 4.4.19(1)-release (x86_64-unknown-linux-gnu)

但在操作系统终端:

art@artPC:~/git/ClanLib$ help
GNU bash, версия 4.4.19(1)-release (x86_64-pc-linux-gnu)

差异为-未知--pc-whoami在两个端子上的结果相同。

最后在VSCode终端:

sh-4.4$ ls
x86_64-unknown-linux-gnu

符号链路x86_64-unknown-linux-gnu的名称在OS和VSCode之间是不同的。VSCode的错误?

解决方案在这里https://github.com/Microsoft/vscode/issues/62532

感谢@jerch 先生

您安装了不同的构建集,请参阅"GNU Make 4.1"与"GNU Mak 4.2.1"。由于某些原因,/bin/sh默认为另一个。要解决这个问题,你必须咨询发行版的帮助(在Ubuntu中,你可以使用updatealternates命令切换构建集(。