{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\Profession\\mingw64\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
2)tasks.json用于配置工程编译参数,参考如下:
{
"tasks": [
{
"type": "shell",
"label": "gcc.exe build active file",
"command": "D:\\Profession\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\build\\${fileBasenameNoExtension}.exe",
"-L", "./main.cpp", // 依次添加.cpp/.c等需要编译的文件
"-L", "D:\\Profession\\mingw64\\x86_64-w64-mingw32\\include", // 添加.hpp/.h等头文件路径
"-I", "D:\\Profession\\mingw64\\x86_64-w64-mingw32\\lib32", // 添加*.lib库文件路径
"-I", "D:\\Profession\\mingw64\\x86_64-w64-mingw32\\lib",
// "-i", "XXX" // 添加具体库文件名,注意:由mingw编译生成的文件不带后缀,如(编译生成XXX.dll.a)
"-Wall",
"-static-libgcc"
],
"options": {
"cwd": "D:\\Profession\\mingw64\\bin"
}
}
],
"version": "2.0.0"
}
此处只编译Main.cpp.
3)launch.json用于配置代码调试参数,参考如下:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"compilerPath": "D:\\Profession\\mingw64\\bin\\gcc.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "clang-x64"
}
],
"version": 4
}
单纯使用gcc编译不适用于大型项目以及三方库较多的项目,因此需要结合cmake进行增量编译。
cmake_minimum_required (VERSION 3.5.1)
project (main)
# 查找当前目录下的所有源文件
# 并将名称保存到 DIR_SRCS 变量
aux_source_directory(. DIR_SRCS)
# 指定生成目标
add_executable(main ${DIR_SRCS})
# 链接库文件
target_link_libraries(main "${TORCH_LIBRARIES}")
set_property(TARGET main PROPERTY CXX_STANDARD 11)
3)在main.cpp同级目录新建build文件夹,在vscode终端中进入build文件夹,并执行cmake -G “Unix Makefiles” …/,生成makefile文件。
4)在build文件夹中执行make,生成main.exe,再输入**.\main.exe**运行。