错误信息:
Undefined symbols for architecture x86_64:
"sum(int, int)", referenced from:
_main in main-81f34d.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
困扰了多天的报错,终于解决了; 哈哈哈,开始撸··
找到setting
将c文件及cpp文件的设置项进行如下修改(报错原因,vs code c++执行器,没有配置执行多文件 //$fileName 修改为 *.cpp)
//$fileName 修改为 *.cpp
"code-runner.executorMap" : {
"c": "cd $dir && gcc *.c -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
"cpp": "cd $dir && g++ *.cpp -o $fileNameWithoutExt && $dir$fileNameWithoutExt",
// "cpp": "cd $dir && g++ $fileName -o $fileNameWithoutExt && $dir$fileNameWithoutExt"
}
VsCode使用Run Code执行多个源文件(下面配置 tasks.json方式好像没用)
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${fileDirname}/*/*.cpp",
"${fileDirname}/*/*.h",
"${fileDirname}/*.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-I",
"${workspaceFolder}/include"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "Task generated by Debugger."
}
],
"version": "2.0.0"
}