项目场景:
自定义了一个swap的头文件,编译不通过
原因分析:
提示:c_cpp_properties.json 和tasks.json 默认只对当前文件编译,如果只选了main.cpp就只会编译这一个文件
解决方案:
提示:修改c_cpp_properties.json 和tasks.json 配置文件,对指定目录下的源文件都进行编译。
c_cpp_properties.json 修改: “includePath”: [ “${workspaceFolder}/**”
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang++",
"cStandard": "c11",
"cppStandard": "c++98",
"intelliSenseMode": "macos-clang-x64"
}
],
"version": 4
}
tasks.json 修改: “-g”, “${fileDirname}/*.cpp”
{
"version": "2.0.0",
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: clang++ 生成活动文件",
"command": "/usr/bin/clang++",
"args": [
"-fdiagnostics-color=always",
"-g",
"${fileDirname}/*.cpp",
"-o",
"${fileDirname}/${fileBasenameNoExtension}"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "编译器: /usr/bin/clang++"
}
]
}
保存后回到项目文件夹,点击空白处shift+command+b 编译 ,再在terminal执行编译完毕的程序 ./main 即可。
|