初学c++ VS code + CMake 编译调试helloWord
来源:互联网 发布:上下课铃声软件 编辑:程序博客网 时间:2024/05/16 14:39
初学c++ VS code + CMake 编译调试helloWord
准备工作
- 安装 VS code
- 安装CMake
- 给VS code安装插件
- c/c++
- c/c++ clang command adapter
- c++ intellisense
- CMake
- CMake Tools
以上插件有的可能是多余 本人也只是在尝试中
设置CMake
首先安装CMake
打开CMake -> tools -> how to install for command line use
这些显示了三种安装方式 我选择第二种
运行 sudo “/Applications/CMake.app/Contents/bin/cmake-gui” –install
配置VS code CMake
进入首选项 -> 设置 添加CMake 路径
“cmake.cmakePath”: “自己CMake的路径”
我的是: “cmake.cmakePath”: “/Applications/CMake.app/Contents/bin/cmake”
编写程序
- 创建项目文件夹
- 创建main.cpp
- 创建CMakeLists.txt
- 创建build文件夹
main.cpp
#include <iostream>using namespace std;int main(int parameter_size, char **parameter){ int a = 1 + 3; int b = a + 3; cout << "hello word " << parameter_size << " " << endl; return 0;}
CMakeLists.txt
#项目名称project(hello_word)#代码路径aux_source_directory(. DIR_TOOT_SRCS)#dubug 模式set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")#生成可执行的文件add_executable(hello_word ${DIR_TOOT_SRCS})
在终端进入build文件夹下运行
cmake ../make
结果如下
fanbindeMBP:build fanbin$ cmake ../-- The C compiler identification is AppleClang 9.0.0.9000037-- The CXX compiler identification is AppleClang 9.0.0.9000037-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc -- works-- Detecting C compiler ABI info-- Detecting C compiler ABI info - done-- Detecting C compile features-- Detecting C compile features - failed-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++-- Check for working CXX compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -- works-- Detecting CXX compiler ABI info-- Detecting CXX compiler ABI info - done-- Detecting CXX compile features-- Detecting CXX compile features - failedCMake Warning (dev) in CMakeLists.txt: No cmake_minimum_required command is present. A line of code such as cmake_minimum_required(VERSION 3.10) should be added at the top of the file. The version specified may be lower if you wish to support older CMake versions for this project. For more information run "cmake --help-policy CMP0000".This warning is for project developers. Use -Wno-dev to suppress it.-- Configuring done-- Generating done-- Build files have been written to: /Users/fanbin/Documents/c:c++/helloword/buildfanbindeMBP:build fanbin$ makeScanning dependencies of target hello_word[ 50%] Building CXX object CMakeFiles/hello_word.dir/main.o[100%] Linking CXX executable hello_word
这时build目录下会生成:
hello_word 文件就是可执行文件了
运行
fanbindeMBP:build fanbin$ ./hello_wordhello word 1
以上我们就成功的编译和运行了
断点调试
点击调试
在调试那里 添加配置
会生成launch.json
按照以下修改 其他可以不变
launch.json
{ "version": "0.2.0", "configurations": [ { "name": "(lldb) hello_word", // 项目名字 "type": "cppdbg", "request": "launch", "program": "${workspaceRoot}/helloword/build/hello_word", //修改这里路径指向刚才生成的可执行程序 "args": [], "args": [], "stopAtEntry": false, "cwd": "${workspaceRoot}", "environment": [], "externalConsole": true, "MIMode": "lldb" } ] }
运行调试 如图
注意 需要在CMakeLists.txt 里加
set (CMAKE_CXX_FLAGS “${CMAKE_CXX_FLAGS} -g”)
开启debug 不然断点调试是无效的
如需去除dubug 只要去掉此行了
阅读全文
0 0
- 初学c++ VS code + CMake 编译调试helloWord
- 初学C#,helloword
- 使用VS Code编译调试C++程序
- Ubuntu 下VS Code 调试C代码
- cmake修改vs--release调试
- 解决VS Code编译调试中文输出乱码
- 在Linux中使用VS Code编译调试C++项目
- Linux中使用VS Code编译调试C++项目详解
- window7 环境下VS CODE编译调试C++程序配置
- 在Linux中使用VS Code编译调试C++项目
- 在Linux中使用VS Code编译调试C++项目
- VS Code调试配置
- VS Code调试js
- 使用VS Code编译运行C/C++程序
- CMake 编译支持GDB调试
- [C编译器]在VS中编译调试C程序
- 在Linux中使用VS Code编译调试C++项目(gcc/g++、Makefile入门、vs code)
- Cmake编译OpenCV和如何在VS工程中配置来使用编译后的OpenCV进行跟踪调试问题
- 列式存储的 parquet文件底层格式
- Happy Happy Prime Prime UVALive
- 那一年,我去了清华园,你去了阿里巴巴
- Java double的精度问题-BigDecimal的用法
- httpclient post请求返回301解决方案
- 初学c++ VS code + CMake 编译调试helloWord
- java基本线程机制
- 抱歉,老师讲得好不好,不是你们学生能评判得了的!
- 从RDD转换得到DataFrame
- select、poll、epoll 比较
- SqlServer数据库将单用户模式变成多用户模式的方法
- Java 判断一个点是否在一个三角形内
- String和StringBuffer区别
- python matplotlib.subplot绘制子图