我不熟悉 c 编译器,我知道如何在终端中使用 gcc 或 g++
我有
主程序
#include <stdio.h>
int count;
extern void write_extern();
int main()
{
count = 5;
write_extern();
}
支持.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-217186.o 中的 _main ld:未找到架构 x86_64 的符号:错误:链接器命令失败,退出代码为 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"
}
如何配置这个?