枣庄高端网站建设,百度做的网站字体侵权,哪家公司建网站好,一起做网店官网下载VSCode 编写 C #xff08;.h#xff0c;.cpp 文件分离#xff09;代码#xff0c;编写完成后#xff0c;编译遇到了编译错误 undefined reference to xxx。 开始还以为使用了 -stdc20 而不能使用 #include “xxx.h 方式头文件#xff0c;但仔细一想虽然引入了 im…
VSCode 编写 C .h.cpp 文件分离代码编写完成后编译遇到了编译错误 undefined reference to xxx。 开始还以为使用了 -stdc20 而不能使用 #include “xxx.h 方式头文件但仔细一想虽然引入了 import也不至于向前兼容都成了问题。
接着觉得可能是没有编译全部的 .cpp 文件只编译了当前执行的 main.cpp文件导致找不到对应的类。试着 #include ”xxx.cpp就解决了问题但也不能这样改呀是不。
这时问题已经明了了在 tasks.json 文件里配置了单文件编译问题就出在这里。修改tasks.json文件中args栏的 ${file} 为 ${fileDirname}\\*.cpp。 至此问题解决。
配置多 tasks并设置快捷键
{version: 2.0.0,tasks: [{type: cppbuild,label: GCC Compile Multi-Cpps,command: C:\\CplusEnv\\mingw64\\bin\\g.exe,args: [-stdc20,-fdiagnostics-coloralways,-g,//${file}, // 编译当前打开(编辑)的 .cpp 文件${fileDirname}/*.cpp, // 编译当前打开的文件所在目录下的所有.cpp 文件-o,${fileDirname}\\${fileBasenameNoExtension}.exe],options: {cwd: ${fileDirname}},problemMatcher: [$gcc],group: {kind: build,isDefault: true},detail: compiler: C:\\CplusEnv\\mingw64\\bin\\g.exe},{type: cppbuild,label: GCC Compile Single-Cpp,command: C:\\CplusEnv\\mingw64\\bin\\g.exe,args: [-stdc20,-fdiagnostics-coloralways,-g,${file}, // 编译当前打开(编辑)的 .cpp 文件//${fileDirname}/*.cpp, // 编译当前打开的文件所在目录下的所有.cpp 文件-o,${fileDirname}\\${fileBasenameNoExtension}.exe],options: {cwd: ${fileDirname}},problemMatcher: [$gcc],group: {kind: build,//isDefault: true},detail: compiler: C:\\CplusEnv\\mingw64\\bin\\g.exe},]
}
配置快捷键
// Place your key bindings in this file to override the defaults
[{key: ctrl1, // 配置快捷键command: workbench.action.tasks.runTask, // runtask//args: GCC Compile Multi-Cpps // task 的名称对应定义的label不定义更换可以弹框选择对应的task},{key: ctrl2,command: workbench.action.tasks.runTask,args: GCC Compile Single-Cpp}
]
按 ctrl1 后出现 按 ctrl2 直接以单文件方式编译。
为什么只编译不运行呢等待后续解决。