vscode c++ cmake工程示例
发布日期:2022-03-11 10:18:56 浏览次数:16 分类:技术文章

本文共 1702 字,大约阅读时间需要 5 分钟。

 

工程目录:

 

源码文件:

#include 
   
    #include 
    
     void print(){
     
for (int i = 0; i < 10; i++)
{
std::cout << "Thread 1: " << i << std::endl;
}}int main(){
std::thread print_thread(print);
print_thread.join();
return 0;}

CmakeList.txt

cmake_minimum_required(VERSION 3.5)project(thread_demo)option(BUILD_DEBUG "Build Debug" ON)set(CMAKE_C_COMPILER "gcc")set(CMAKE_CXX_COMPILER "g++")if(BUILD_DEBUG)
message("Build Debug Mode")
set(CMAKE_BUILD_TYPE Debug)
set(CMAKE_CXX_FLAGS "-fPIC -std=c++11 -O0 -g ${CMAKE_CXX_FLAGS}")else()
message("Build Release Mode")
set(CMAKE_BUILD_TYPE Release)
set(CMAKE_CXX_FLAGS "-fPIC -std=c++11 -O3 ${CMAKE_CXX_FLAGS}")endif(BUILD_DEBUG)set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)set(LIBRARY_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/lib)add_executable(main main.cpp)target_link_libraries(main -lpthread)

tasks.json:

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

launch.json:

{
"version": "0.2.0",
"configurations": [
{
"name": "g++ - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/bin/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "Build",
"miDebuggerPath": "/usr/bin/gdb"
}
]}

代码调试:

 

 

转载地址:https://blog.csdn.net/weicao1990/article/details/109702276 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:skimage-SimilarityTransform的C++实现
下一篇:Caffe中的crop_layer层

发表评论

最新留言

很好
[***.244.66.235]2022年10月02日 01时29分17秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

最新文章