【发布时间】:2016-10-18 07:06:11
【问题描述】:
我尝试在 CLIon ide 中编译一个简单的 POSIX 示例,但它不知道 pthread 库,我认为... 代码如下:
void *func1()
{
int i;
for (i=0;i<10;i++) { printf("Thread 1 is running\n"); sleep(1); }
}
void *func2()
{
int i;
for (i=0;i<10;i++) { printf("Thread 2 is running\n"); sleep(1); }
}
int result, status1, status2;
pthread_t thread1, thread2;
int main()
{
result = pthread_create(&thread1, NULL, func1, NULL);
result = pthread_create(&thread2, NULL, func2, NULL);
pthread_join(thread1, &status1);
pthread_join(thread2, &status2);
printf("\nПотоки завершены с %d и %d", status1, status2);
getchar();
return 0;
}
众所周知,这段代码是正确的,因为它取自书中的示例。所以 Clion 将 pthread_join 函数的第二个参数标记为错误,给出这个错误:
error: invalid conversion from ‘void* (*)()’ to ‘void* (*)(void*)’
我想,问题出在 CmakeList 中。这是我当前的 CMakeList:
cmake_minimum_required(VERSION 3.3)
project(hello_world C CXX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
set(SOURCE_FILES main.cpp)
add_executable(hello_world ${SOURCE_FILES})
【问题讨论】:
-
在“已知”之后有“,”而不是“?”
标签: cmake pthreads posix clion