提问人:Gil 提问时间:11/11/2023 更新时间:11/11/2023 访问量:24
在构建时处理 pthread 宏错误?
Handeling pthread Macro Error at Build Time?
问:
我已经在很长一段时间内遇到同样的错误了。下面的 C++ 示例被简化,因为我第一次遇到此错误是在构建新下载的库时。我不知道如何处理这个问题。我已经重新下载了 g++、gcc、essential build 和 libc6。
下面是一个基本的 C++ 代码来演示错误:
#include <iostream>
#include <pthread.h>
int main() {
pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
pthread_mutex_destroy(&m);
std::cout << "Hello, World!" << std::endl;
return 0;
}
以下是CMakeLists.txt文件:
project(clion_pthread)
set(CMAKE_CXX_STANDARD 14)
# Find the Threads package (this finds pthreads on UNIX)
find_package(Threads REQUIRED)
# Add your executable
add_executable(clion_pthread main.cpp)
# Link the executable to the Threads library
target_link_libraries(clion_pthread Threads::Threads)
错误
clion_pthread/cmake-build-debug --target clion_pthread -- -j 6
[ 50%] Building CXX object CMakeFiles/clion_pthread.dir/main.cpp.o
In file included from /usr/include/x86_64-linux-gnu/c++/9/bits/gthr-default.h:35,
from /usr/include/x86_64-linux-gnu/c++/9/bits/gthr.h:148,
from /usr/include/c++/9/ext/atomicity.h:35,
from /usr/include/c++/9/bits/ios_base.h:39,
from /usr/include/c++/9/ios:42,
from /usr/include/c++/9/ostream:38,
from /usr/include/c++/9/iostream:39,
from /clion_pthread/main.cpp:1:
clion_pthread/main.cpp: In function ‘int main()’:
clion_pthread/main.cpp:5:25: error: ‘__PTHREAD_SPINS’ was not declared in this scope
5 | pthread_mutex_t m = PTHREAD_MUTEX_INITIALIZER;
| ^~~~~~~~~~~~~~~~~~~~~~~~~
make[3]: *** [CMakeFiles/clion_pthread.dir/build.make:76: CMakeFiles/clion_pthread.dir/main.cpp.o] Error 1
make[2]: *** [CMakeFiles/Makefile2:83: CMakeFiles/clion_pthread.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:90: CMakeFiles/clion_pthread.dir/rule] Error 2
make: *** [Makefile:124: clion_pthread] Error 2
操作系统
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.6 LTS
Release: 20.04
Codename: focal
答: 暂无答案
评论
pthread
pthread
pthread