使用c++线程获得错误
Get an error using c++ threads
我正在编写一个程序,它通过使用一个线程来改变许多窗口的焦点。
pthread_t getFocus;
pthread_create ( &getFocus, NULL, returnFocus, NULL );
pthread_join ( getFocus, NULL );
void *returnFocus ( void *argument ) {
return 0;
}
编译时,我得到这个错误:
undefined reference to _imp__pthread_create
undefined reference to _imp__pthread_join
我应该怎么做来纠正这个错误?
当使用using pthread时,您还需要使用-lpthread选项链接到pthread库。
gcc -o myprog myprog.c -lpthread
编辑:正如Maxim在评论中所说,这样做的可移植方法是:
gcc -o myprog myprog.c -pthread
-lpthread是Unix的方法(我学过的),但您应该始终使用-pthread,如果不可用(或者如果您有非常特殊的原因),请使用-lpthread。
在linux上-lpthread表示"与pthread库的链接",而-pthread只是说"做你需要为pthread做的事情",从我读到的
相关文章:
- 线程,如果else语句,都是错误的上下文切换后,会发生什么
- C++使用params创建线程函数会导致转换错误
- 是什么导致了Unity 3D中的"错误线程异常"?
- 使用带有 ref 参数的成员函数创建线程时出现编译错误
- 尝试从头开始实现Leetcode的FizzBuzz多线程问题。收到"libc++abi.dylib: terminating"错误
- 线程时访问静态映射时出现隔离错误
- 多线程减慢程序速度:无错误共享,无互斥锁,无缓存未命中,无小工作量
- 我有一个线程 1:EXC_BAD_ACCESS(代码 = 1,地址 = 0x8)错误.我认为这是由于内存管理不好.我可以
- 两个线程一个使用流 Api,另一个线程创建文件失败并出现错误ERROR_SHARING_VIOLATION
- C++多线程程序:变量定义为类成员的隔离错误
- 当 2 个线程共享同一物理内核时,具有错误共享的易失性增量在发布中的运行速度比在调试中慢
- 线程 std::调用未知类型,无法专门化函数错误
- 停止 winapi 线程时出现错误行为
- C++线程错误
- C++线程错误:没有名为"类型"MINGW 的类型
- 可中断线程类 C++11 - 遇到错误?
- 分离的线程:在繁忙时销毁互斥锁 错误C++
- 为同一向量C++运行多个线程时出现分段错误
- 查找最低值.功能.错误:线程 1:EXC_BAD_ACCESS(代码 = 1,地址 = 0x7fff5fc89000)
- MINGW错误:“线程”不是“ STD”的成员