【发布时间】:2020-07-13 02:54:43
【问题描述】:
我不熟悉c编译器,我知道如何在终端中使用gcc或g++
我有
main.c
#include <stdio.h>
int count;
extern void write_extern();
int main()
{
count = 5;
write_extern();
}
support.c
#include <stdio.h>
extern int count;
void write_extern(void)
{
printf("count is %d\n", count);
}
gcc main.c support.c
输出文件 a.out 工作正常
但如果我使用 vscode 或 code-runner 插件进行调试 错误显示
/"主要 架构 x86_64 的未定义符号: “_write_extern”,引用自: _main 在 main-217186.o ld:未找到架构 x86_64 的符号 clang:错误:链接器命令失败,退出代码为 1(使用 -v 查看调用)
我的 launch.json 和 task.json 看起来像这样:
"configurations": [
{
"name": "clang build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/${fileBasenameNoExtension}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"preLaunchTask": "clang build active file"
}
]
{
"tasks": [
{
"type": "shell",
"label": "clang build active file",
"command": "/usr/bin/clang",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "/usr/bin"
}
}
],
"version": "2.0.0"
}
如何配置?
【问题讨论】:
-
似乎 VSCode 只编译 1 个单个文件,这显然是不够的,因为你有 2 个文件。也许这有帮助:stackoverflow.com/questions/47665886/…
标签: c visual-studio-code vscode-code-runner