以前开发 Linux 服务器的程序,会有通过 samba 进行文件保存,或者先在 windows 上编译测试,然后传到 Linux 服务器重新编译测试。这些都不太直接,而且调试起来比较困难。现在很多 IDE 都支持直接编写 LINUX 上的程序了,本文介绍 VSCode 如何完成这个工作。
使用 Visual Studio Code 开发 LINUX 上 C++ 应用 - 腾讯云开发者社区-腾讯云 (tencent.com)
在vscode中按Ctrl+Shift+P 输入configuration 在c_cpp_properties.json中includePath字段中添加待添加的SDK或者库的头文件路径 例:"/usr/local/xxx/include/"
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/thirdparty/**",
"${workspaceFolder}/src/**"
],
"defines": [],
"compilerPath": "/usr/bin/g++",
"cStandard": "gnu11",
"cppStandard": "gnu++14",
"intelliSenseMode": "gcc-x64"
}
],
"version": 4
}
复制
{
"version": "2.0.0",
"tasks": [
{
"type": "shell",
"label": "make demo game_server",
"command": "/usr/bin/make",
"args": [],
"options": {
"cwd": "${workspaceFolder}/demos/demo/server"
},
"problemMatcher":{
"base": "$gcc",
"fileLocation": [
"relative",
"${fileDirname}"
]
},
"group": {
"kind": "build",
"isDefault": true
}
},
{
"type": "shell",
"label": "clean demo game_server",
"command": "/usr/bin/make",
"args": ["clean"],
"options": {
"cwd": "${workspaceFolder}/demos/demo/server"
},
"problemMatcher":{
"base": "$gcc",
"fileLocation": [
"relative",
"${fileDirname}"
]
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
复制
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "调试 demo game_server",
"type": "cppdbg",
"request": "launch",
"program": "
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/demos/demo/server/bin",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "make demo game_server",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
复制
"editor.fontFamily": "JetBrains Mono",
"editor.fontSize": 13,
"editor.fontLigatures": true