IDE Integration¶
This guide covers integrating the Nexus Embedded Platform with popular IDEs including Visual Studio Code, CLion, and Visual Studio.
Visual Studio Code¶
VS Code is a lightweight, cross-platform editor with excellent CMake and C/C++ support.
前置条件¶
Install the following VS Code extensions:
C/C++ (ms-vscode.cpptools) - IntelliSense, debugging
CMake Tools (ms-vscode.CMake-tools) - CMake integration
CMake (twxs.CMake) - CMake language support
Installation:
code --install-extension ms-vscode.cpptools
code --install-extension ms-vscode.CMake-tools
code --install-extension twxs.CMake
配置¶
创建 .vscode/settings.json:
{
"CMake.configureOnOpen": true,
"CMake.buildDirectory": "${workspaceFolder}/build",
"CMake.generator": "Ninja",
"CMake.configureSettings": {
"NEXUS_PLATFORM": "native",
"NEXUS_BUILD_TESTS": "ON",
"NEXUS_BUILD_EXAMPLES": "ON",
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_EXPORT_COMPILE_COMMANDS": "ON"
},
"C_Cpp.default.configurationProvider": "ms-vscode.CMake-tools",
"C_Cpp.default.compileCommands": "${workspaceFolder}/build/compile_commands.json",
"files.associations": {
"*.h": "c",
"*.c": "c"
}
}
Create .vscode/c_cpp_properties.json:
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/gcc",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
},
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.19041.0",
"compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "windows-msvc-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
},
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
}
Create .vscode/launch.json for debugging:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch Tests",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/tests/nexus_tests",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "CMake: build",
"miDebuggerPath": "/usr/bin/gdb",
"linux": {
"MIMode": "gdb",
"miDebuggerPath": "/usr/bin/gdb"
},
"osx": {
"MIMode": "lldb"
},
"windows": {
"MIMode": "gdb",
"miDebuggerPath": "C:\\msys64\\mingw64\\bin\\gdb.exe"
}
},
{
"name": "(gdb) Launch Blinky",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/build/applications/blinky/blinky",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"preLaunchTask": "CMake: build"
}
]
}
Create .vscode/tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "CMake: configure",
"type": "shell",
"command": "CMake",
"args": [
"-B",
"${workspaceFolder}/build",
"-DNEXUS_PLATFORM=native",
"-DCMAKE_BUILD_TYPE=Debug"
],
"group": "build",
"problemMatcher": []
},
{
"label": "CMake: build",
"type": "shell",
"command": "CMake",
"args": [
"--build",
"${workspaceFolder}/build",
"--",
"-j4"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": ["$gcc"],
"dependsOn": ["CMake: configure"]
},
{
"label": "CMake: clean",
"type": "shell",
"command": "CMake",
"args": [
"--build",
"${workspaceFolder}/build",
"--target",
"clean"
],
"group": "build",
"problemMatcher": []
},
{
"label": "Run Tests",
"type": "shell",
"command": "ctest",
"args": [
"--test-dir",
"${workspaceFolder}/build",
"--output-on-failure"
],
"group": "test",
"problemMatcher": [],
"dependsOn": ["CMake: build"]
}
]
}
用法¶
Open Project:
File > Open Folderand select the Nexus root directoryConfigure: Press
Ctrl+Shift+Pand runCMake: ConfigureBuild: Press
Ctrl+Shift+Pand runCMake: Buildor pressF7Run Tests: Press
Ctrl+Shift+Pand runCMake: Run TestsDebug: Press
F5to start debugging
Keyboard Shortcuts¶
F7- BuildF5- Start debuggingShift+F5- Stop debuggingF9- Toggle breakpointF10- Step overF11- Step intoShift+F11- Step out
CLion¶
CLion is a cross-platform C/C++ IDE from JetBrains with native CMake support.
前置条件¶
CLion automatically detects CMake projects. Ensure you have:
CLion 2020.3 or later
CMake 3.16 or later
C/C++ compiler (GCC, Clang, or MSVC)
ARM GCC toolchain (for embedded targets)
配置¶
CLion automatically detects CMake projects. No additional configuration is required for basic usage.
Custom CMake Options¶
Open
File > Settings > Build, Execution, Deployment > CMakeAdd build profiles:
Debug Profile:
Name:
DebugBuild type:
DebugCMake options:
-DNEXUS_PLATFORM=native -DNEXUS_BUILD_TESTS=ONBuild directory:
build-Debug
Release Profile:
Name:
ReleaseBuild type:
ReleaseCMake options:
-DNEXUS_PLATFORM=native -DNEXUS_BUILD_TESTS=OFFBuild directory:
build-Release
STM32F4 Profile:
Name:
STM32F4Build type:
ReleaseCMake options:
-DNEXUS_PLATFORM=stm32f4 -DNEXUS_BUILD_TESTS=OFFBuild directory:
build-stm32f4Toolchain:
ARM GCC(configure inFile > Settings > Build, Execution, Deployment > Toolchains)
工具链 配置¶
For ARM cross-compilation:
Open
File > Settings > Build, Execution, Deployment > ToolchainsAdd new toolchain:
Name:
ARM GCCC Compiler:
/usr/bin/arm-none-eabi-gcc(or Windows path)C++ Compiler:
/usr/bin/arm-none-eabi-g++Debugger:
/usr/bin/arm-none-eabi-gdb
Run/Debug Configurations¶
CLion automatically creates run configurations for executables.
To create a custom configuration:
Run > Edit ConfigurationsAdd new
CMake Application:
Name:
Nexus TestsTarget:
nexus_testsExecutable:
nexus_testsProgram arguments:
--gtest_filter=*
用法¶
Open Project:
File > Openand selectCMakeLists.txtReload CMake:
Tools > CMake > Reload CMake ProjectBuild:
Build > Build ProjectorCtrl+F9Run:
Run > RunorShift+F10Debug:
Run > DebugorShift+F9Run Tests: Right-click on
testsfolder and selectRun Tests
Keyboard Shortcuts¶
Ctrl+F9- Build projectShift+F10- RunShift+F9- DebugCtrl+F8- Toggle breakpointF8- Step overF7- Step intoShift+F8- Step out
Visual Studio¶
Visual Studio 2019/2022 has native CMake support.
前置条件¶
Install Visual Studio with:
Desktop development with C++ workload
C++ CMake tools for Windows component
C++ Clang tools for Windows (optional)
配置¶
Visual Studio uses CMakeSettings.json for configuration.
Create CMakeSettings.json:
{
"configurations": [
{
"name": "x64-Debug",
"generator": "Ninja",
"configurationType": "Debug",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\install\\${name}",
"cmakeCommandArgs": "-DNEXUS_PLATFORM=native -DNEXUS_BUILD_TESTS=ON",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"variables": [
{
"name": "CMAKE_BUILD_TYPE",
"value": "Debug",
"type": "STRING"
},
{
"name": "NEXUS_PLATFORM",
"value": "native",
"type": "STRING"
},
{
"name": "NEXUS_BUILD_TESTS",
"value": "ON",
"type": "BOOL"
}
]
},
{
"name": "x64-Release",
"generator": "Ninja",
"configurationType": "Release",
"inheritEnvironments": [ "msvc_x64_x64" ],
"buildRoot": "${projectDir}\\build\\${name}",
"installRoot": "${projectDir}\\install\\${name}",
"cmakeCommandArgs": "-DNEXUS_PLATFORM=native -DNEXUS_BUILD_TESTS=OFF",
"buildCommandArgs": "",
"ctestCommandArgs": "",
"variables": [
{
"name": "CMAKE_BUILD_TYPE",
"value": "Release",
"type": "STRING"
}
]
}
]
}
用法¶
Open Project:
File > Open > CMakeand selectCMakeLists.txtSelect Configuration: Use the configuration dropdown in the toolbar
Build:
Build > Build AllorCtrl+Shift+BRun Tests:
Test > Run All TestsDebug: Set breakpoints and press
F5
测试 Explorer¶
Visual Studio integrates with Google Test:
Open
Test > Test ExplorerTests appear automatically after building
Run individual tests or test suites
View test output and failures
Keyboard Shortcuts¶
Ctrl+Shift+B- Build solutionF5- Start debuggingCtrl+F5- Start without debuggingShift+F5- Stop debuggingF9- Toggle breakpointF10- Step overF11- Step intoShift+F11- Step out
ARM Cross-Compilation in Visual Studio¶
For ARM targets, use Visual Studio with external toolchain:
Install ARM GCC toolchain
Create ARM configuration in
CMakeSettings.json:
{
"name": "ARM-STM32F4",
"generator": "Ninja",
"configurationType": "Release",
"buildRoot": "${projectDir}\\build\\${name}",
"cmakeCommandArgs": "-DNEXUS_PLATFORM=stm32f4 -DCMAKE_TOOLCHAIN_FILE=CMake/toolchains/arm-none-eabi.CMake",
"variables": [
{
"name": "TOOLCHAIN_PREFIX",
"value": "C:/Program Files (x86)/GNU Arm Embedded Toolchain/10 2021.10",
"type": "PATH"
}
]
}
Build using this configuration
Common Issues¶
VS Code¶
IntelliSense not working
Solution: Ensure compile_commands.json is generated:
CMake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ..
CMake Tools extension not detecting project
Solution: Reload window (Ctrl+Shift+P > Developer: Reload Window)
CLion¶
CMake errors on project open
Solution: Check CMake version and ensure all dependencies are installed.
Toolchain not found
Solution: Configure toolchain in File > Settings > Build, Execution, Deployment > Toolchains
Visual Studio¶
CMake configuration fails
Solution: Check Output > CMake window for errors. Ensure CMake 3.16+ is installed.
Tests not appearing in Test Explorer
Solution: Rebuild project and refresh Test Explorer.
另请参阅¶
构建系统 - Build system documentation
测试 - Testing guide
Environment Setup - Installation guide