For friends who are used to the Ubuntu environment, it is very troublesome to configure the VS CODE and C/C++ environment under windows. Don't worry, let me take you five minutes to set it up.
Environment installation
First, we need to download and install 3 things, vscode, mingw64 (c/c++ compiler), cmake (compilation manager).
Paste the link:
CMAKE download
MINGW64 download
VSCODE download
CMAKE and VSCODE After downloading, you can directly open the installation in the next step. Note, if there is an option to add environment variables, remember to check it. MINGW64 is downloaded as a compressed package, and we put it in the C drive directory.
Configure environment variables
After installation, we also need to configure environment variables so that the windows system can find the three software we installed.
Just do the following, remember to change the path to your own:
VSCODE configuration
Just install the two in the red box in the plug-in store. This is the c++ and cmake collection package. The code Runner is also recommended to install.
Next, create a folder, open it with vscode, and create a new main.cpp
Then follow this step to generate configuration files and folders. Note that this is a hidden folder. You need to enable the display of hidden files to see it.
Finally, create these json files and paste the following code into them
c_cpp_properties.json
{
"configurations": [
{
"name": "win64",
"includePath": [
"${workspaceFolder}/**",
"${workspaceRoot}/include/"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "8.1",
"compilerPath": "C:/mingw64/bin/g++.exe",
"cStandard": "c11",
"cppStandard": "c++11",
"intelliSenseMode": "gcc-x64",
"configurationProvider": "ms-vscode.cmake-tools"
}
]
,
"version": 4
}
launch.json
{
"version": "0.2.0",
"configurations": []
}
settings.json
{
"files.associations": {
"iostream": "cpp",
"ostream": "cpp",
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"optional": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iosfwd": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
}
}
tasks.json
{
"tasks": [
{
"type": "cppbuild",
"label": "C/C++: g++.exe 生成活动文件",
"command": "C:\\mingw64\\bin\\g++.exe",
"args": [
"-fdiagnostics-color=always",
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${fileDirname}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
},
"detail": "调试器生成的任务。"
}
],
"version": "2.0.0"
}
If the installation path of your mingw64 and the like is different from mine, remember to change it to your own.
CMAKE configuration
Finally, we create a CMakeLists.txt, and then we can happily run the code.
Here is an example, using the npcap library, CMakeLists can refer to mine.
I use include to install header files, Lib to install link libraries, you can configure according to your own, and change it to the corresponding one in CMakeLists
cmake_minimum_required(VERSION 3.0)
project(pcap_parser)
set(CMAKE_CXX_STANDARD 11)
include_directories(./include)
link_directories(./Lib)
add_executable(pcap_parser main.cpp)
target_link_libraries(pcap_parser wpcap)
target_link_libraries(pcap_parser Packet)
Finally, click this to call cmake to compile and run