c++ - 在 C++ 中使用 Boost Threads 的基本程序的问题

标签 c++ boost multithreading

我有一个简单的程序,它在 C++ 中使用 boost 线程作为线程创建和执行。

#include<boost/thread/thread.hpp>
#include<iostream>


void hello()
{

    std::cout<<"Hello, i am a thread"<<std::endl;

}

int main()
{
    boost::thread th1(&hello);
    th1.join();


}

编译器针对 th1.join() 行抛出错误。它说 "
此行有多个标记

- undefined reference to 

 `boost::thread::join()'

- undefined reference to 

 `boost::thread::~thread()'

最佳答案

这绝对是没有包含适当的 header /链接库的问题。

1) 您应该检查您的包含路径是否有适当的 boost 文件夹和 boost header 。 2) 您应该使用适当的静态库 (xxx.lib) 文件构建您的应用程序。对于 boost::thread,该文件将被命名为类似于 libboost_thread_xxx.lib

关于c++ - 在 C++ 中使用 Boost Threads 的基本程序的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2836075/

相关文章:

c++ - Boost::posix_time::ptime舍入到给定的分钟数

multithreading - 使用 OmniThreadLibrary 并行写入数组比串行写入慢

android - 我如何在android中的线程中加载图像

multithreading - 无锁算法真的比全锁算法性能更好吗?

c++ - 如何声明指向成员模板函数的指针?

python - pyLCIO setMomentum : error const float* in python

c++ - 在 C++ 中分割一个大文件

c++ - 一个类中有多个构造函数

c++ - Boost 或标准库是否提供了一种方法来检查转换是否无损?

C++函数转换题