【Mac M1|C++】Macbook M1下使用VScode调试运行C++
·
VScode插件


launch.json

{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Debug",
"program": "${workspaceFolder}/build/1",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": true,
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
"targetArchitecture": "arm64"
}
]
}
task.json

{
"version": "2.0.0",
"options": {
"cwd": "${workspaceFolder}/build"
},
"tasks": [
{
"type": "shell",
"label": "cmake",
"command": "cmake",
"args": [
".."
]
},
{
"label": "make",
"group": {
"kind": "build",
"isDefault": true
},
"command": "make",
"args": [
]
},
{
"label": "Build",
"dependsOrder": "sequence",
"dependsOn":[
"cmake",
"make"
]
}
]
}
c_cpp_properties.json

{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**",
"/usr/local/include",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/c++/v1",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/13.0.0/include",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include",
"/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include",
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/opt/homebrew/bin/gcc-11",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "macos-gcc-arm64"
}
],
"version": 4
}
执行:
g++ -v -E -x c++ -
输出:

框出的部分填入c_cpp_properties.json中
CMakeLists.txt
cmake_minimum_required(VERSION 2.6 FATAL_ERROR)
project(LeetCode)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall") # 显示代码警告
set(CMAKE_BUILD_TYPE Debug) # 设置Debug模式,否则无法在断点处停下
add_executable(1 1.cpp)
target_link_libraries(1)
目录结构

运行

更多推荐



所有评论(0)