当前位置: 首页 > news >正文

关于ubuntu环境下vscode进行debug的随笔

CMakeLists.txt的编写

顶层目录的CMakelists.txt

  1. 目录:./CMakeLists.txt
#./CMakeLists.txt
cmake_minimum_required(VERSION 3.10)
project(xxx_project_name LANGUAGES CXX)		#设置工程名# 设置 C++ 标准和编译选项
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -msse4.1")  # 启用 SSE4.1 优化#配置是debug OR release
if(NOT CMAKE_BUILD_TYPE)set(CMAKE_BUILD_TYPE Release)message(STATUS "Build type not specified: defaulting to Release.")
endif(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE ${CMAKE_BUILD_TYPE} CACHE STRING "")#添加动态库
link_libraries(m)
link_libraries(pthread)#添加目录所有.c/cpp 到 DIR_SRCS
#aux_source_directory(<dir> <var>)只收集c/cpp、不递归、不感知新增文件
aux_source_directory(. DIR_SRCS) 
#file(GLOB <var> <pattern>) 自定义收集文件、支持递归、新增文件需要重新运行cmake、可能匹配多余文件,如备份文件
file(GLOB SOURCES "*.cpp")       # 手动指定通配符模式
file(GLOB_RECURSE SOURCES "src/**/*.cpp")  # 递归
#set(<var> <filelist>) 维护成本高
set(SOURCES "main.cpp" "util.cpp")  # 显式列出所有文件include_directories(${PROJECT_BINARY_DIR}/lib/include)
include_directories(${PROJECT_SOURCE_DIR}/lib/include)# generate executalbe file
add_executable(xxx_project_name ${DIR_SRCS})# 额外
# 添加 需要子目录
add_subdirectory(lib)
add_subdirectory(utils)
add_subdirectory(common)
# 添加链接库
target_link_libraries(xxx_project_name utils)
target_link_libraries(xxx_project_name ch_estimation)
target_link_libraries(xxx_project_name common)

2.1 ./utils/CMakeLists.txt

# ./utils/CMakeLists.txt
# 查找当前目录下的所有源文件
# 并将名称保存到 DIR_LIB_SRCS 变量
aux_source_directory(. DIR_LIB_SRCS)# 生成链接库
add_library (utils ${DIR_LIB_SRCS})

./lib/CMakeLists.txt

#./lib/CMakeLists.txtadd_subdirectory(src)
add_subdirectory(include)
add_subdirectory(examples)
add_subdirectory(test)INSTALL(  DIRECTORY include/DESTINATION "${INCLUDE_DIR}"FILES_MATCHING PATTERN "*.h" )

./lib/src/CMakeLists.txt

#./lib/src/CMakeLists.txt
add_subdirectory(phy)

./lib/src/phy/CMakeLists.txt

#./lib/src/phy/CMakeLists.txt
add_subdirectory(phch)set(srsran_srcs $<TARGET_OBJECTS:srsran_phch>)
#$<TARGET_OBJECTS:target_name> 生成器表达式        
#​功能​:获取指定目标(通常是对象库)编译生成的 ​对象文件列表​(.obj/.o 文件)#使用前提​:
#target_name 必须是已定义的对象库(OBJECT 库)
#对象库通过 add_library(... OBJECT) 声明add_library(srsran_phy STATIC ${srsran_srcs})
target_link_libraries(srsran_phy pthread m ${FFT_LIBRARIES})
install(TARGETS srsran_phy DESTINATION ${LIBRARY_DIR} OPTIONAL)

.\lib\src\phy\phch\CMakeLists.txt

# .\lib\src\phy\phch\CMakeLists.txt
file(GLOB SOURCES "*.c")
add_library(xxx_sf1_1_name OBJECT ${SOURCES})
add_subdirectory(sf1_1_1_name)

.\lib\src\phy\phch\test\CMakeLists.txt

# .\lib\src\phy\phch\test\CMakeLists.txt
set(CTEST_LABELS "lib;phy;phch")
add_executable(pmch_test pmch_test.c)
target_link_libraries(pmch_test srsran_phy)

vscode::tasks.json

此时需要注意:

  • 如果在CMakeLists.txt文件中对CMAKE_BUILD_TYPE的设置是Release时,想要在vscode进行单步调试,需要在cmake configure这个过程中添加-DCMAKE_BUILD_TYPE=Debug
  • 参数里面的"-S",“${workspaceFolder}”等价于
{"version": "2.0.0","tasks": [{"label": "CMake: Configure","type": "cppbuild","command": "cmake","args": ["-S", "${workspaceFolder}","-B", "${workspaceFolder}/build",// "-G", "Ninja",//如果在CMakeLists.txt文件中设置的是//set(CMAKE_BUILD_TYPE Release CACHE STRING "")时//想step debug,需要如下配置"-DCMAKE_BUILD_TYPE=Debug",//"-DCMAKE_BUILD_TYPE=Release",],"options": {"cwd": "${fileDirname}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"detail": "Task generated by Debugger."},{"label": "CMake: build","type": "cppbuild","command": "make","args": ["-C", "${workspaceFolder}/build","-j", "4","all"],"options": {"cwd": "${fileDirname}"},"problemMatcher": ["$gcc"],"group": {"kind": "build","isDefault": true},"dependsOn":["CMake: Configure"],"detail": "Task generated by Debugger."},],
}

vscode::launch.json

{// Use IntelliSense to learn about possible attributes.// Hover to view descriptions of existing attributes.// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387"version": "0.2.0","configurations": [       {"name": "(gdb) Launch","type": "cppdbg","request": "launch","program": "${workspaceFolder}/build/modem","args": [],"stopAtEntry": false,"cwd": "${fileDirname}","environment": [],"externalConsole": false,"MIMode": "gdb","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true},{"description": "Set Disassembly Flavor to Intel","text": "-gdb-set disassembly-flavor intel","ignoreFailures": true}],"preLaunchTask": "CMake: build",},{"name": "(gdb) Launch pmch_test","type": "cppdbg","request": "launch","program": "${workspaceFolder}/buildM/lib/src/phy/phch/test/pmch_test","args": [],"stopAtEntry": false,"cwd": "${workspaceFolder}/buildM/lib/src/phy/phch/test/","environment": [],"externalConsole": false,"MIMode": "gdb","setupCommands": [{"description": "Enable pretty-printing for gdb","text": "-enable-pretty-printing","ignoreFailures": true},{"description": "Set Disassembly Flavor to Intel","text": "-gdb-set disassembly-flavor intel","ignoreFailures": true}],"preLaunchTask": "CMake: build",},]
}
http://www.lqws.cn/news/459505.html

相关文章:

  • 【工具教程】识别PDF中文字内容,根据文字内容对PDF批量重命名,提取识别PDF内容给图片重新命名的操作步骤和注意事项
  • 第十三章 模板
  • 机器学习流量识别(pytorch+NSL-KDD+多分类建模)
  • 自动化性能回退机制——蓝绿部署与灰度发布
  • 前端 CSS 框架:分类、选择与应用
  • 「AI高校」| 《清华大学:AI赋能教育高考志愿填报工具使用指南》
  • 新品上市 | 尺寸小且具有丰富接口的读卡器:RFID高频系列CK-FR06
  • MySQL之事务深度解析
  • django FileSystemStorage is located outside of the base path component
  • Android Studio报错:Could not move temporary workspace () to immutable location
  • NY339NY341美光固态闪存NW841NW843
  • MySQL入门初解
  • 数据分析和可视化:Py爬虫-XPath解析章节要点总结
  • 【Dify学习笔记】:RagFlow接入Dify基础教程
  • Real-World Deep Local Motion Deblurring论文阅读
  • Linux——linux的基本命令
  • ceph 自动调整 pg_num
  • 链接过程使用链接器将该目标文件与其他目标文件、库文件、启动文件等链接起来生成可执行文件。附加的目标文件包括静态连接库和动态连接库。其中的启动文件是什么意思?
  • SpringMVC知识点总结
  • python自助棋牌室管理系统
  • golang编译时传递参数或注入变量值到程序中
  • JVM对象内存分配机制全解析
  • Springboot仿抖音app开发之Nacos 分布式服务与配置中心(进阶)
  • C/C++ 高频八股文面试题1000题(一)
  • 408第二季 - 组成原理 - 流水线
  • 开疆智能ModbusTCP转EtherCAT网关连接IVO编码器配置案例
  • Python 的内置函数 globals
  • [MSPM0开发]之九 MSPM0G3507的ADC
  • 全球首款5G-A人形机器人亮相,通信与AI融合进入新阶段
  • 展锐android13修改开机logo和开机图片