clion编写C++ 使用多线程时候,CMakeLists.txt书写,引用-pthread
                                                            生活随笔
收集整理的這篇文章主要介紹了
                                clion编写C++ 使用多线程时候,CMakeLists.txt书写,引用-pthread
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.                        
                                添加如下一行
- set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
具體的例子
cmake_minimum_required(VERSION 3.17) project(mutex_learn)set(CMAKE_CXX_STANDARD 14)set(BOOST_ROOT "/usr/local/include/boost") #添加頭文件搜索路徑 include_directories(/usr/local/include) #添加庫文件搜索路徑 link_directories(/usr/local/lib)add_executable(mutex_learn main.cpp) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") #set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -lrt")target_link_libraries(mutex_learn boost_thread boost_system rt)完整代碼
#include <sys/shm.h> #include <iostream> #include <unistd.h> #include <pthread.h>void * child1(void *arg){pthread_t tid = pthread_self();printf("1 thread %lu \n",tid);}int main(int argc,char* argv[]) {int result{};pthread_t a_thread{};pthread_t tid = pthread_self();printf("mean thread %lu \n",tid);result = pthread_create(&a_thread, nullptr,child1, nullptr);if (result !=0){printf("Thread create failed!");}return 0; }總結
以上是生活随笔為你收集整理的clion编写C++ 使用多线程时候,CMakeLists.txt书写,引用-pthread的全部內容,希望文章能夠幫你解決所遇到的問題。
 
                            
                        - 上一篇: Linux进程之间通信 消息队列
- 下一篇: 中信腾讯微加信用卡怎么激活使用?这些事项
