Boost C ++的架构x86_64的未定义符号

busebd12

我正在尝试为Boost库编译以下简单线程示例:

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

        using namespace std;

        void thread()
        {
          for (int i = 0; i < 5; ++i)
          {
            cout << i << '\n';
          }
        }

        int main()
        {
          boost::thread t{thread};
          t.join();
        }

使用

  g++ -std=c++11 -I /usr/local/boost_1_57_0 simpleThreadExample.cpp

编译器将此反馈给我:

       Undefined symbols for architecture x86_64:
        "boost::detail::thread_data_base::~thread_data_base()", referenced from:
        boost::detail::thread_data<void (*)()>::~thread_data() in simpleThreadExample-7cec5e.o
        "boost::system::system_category()", referenced from:
        ___cxx_global_var_init2 in simpleThreadExample-7cec5e.o
        boost::thread_exception::thread_exception(int, char const*) in simpleThreadExample-7cec5e.o
       "boost::system::generic_category()", referenced from:
      ___cxx_global_var_init in simpleThreadExample-7cec5e.o
      ___cxx_global_var_init1 in simpleThreadExample-7cec5e.o
      "boost::thread::join_noexcept()", referenced from:
          boost::thread::join() in simpleThreadExample-7cec5e.o
      "boost::thread::native_handle()", referenced from:
          boost::thread::get_id() const in simpleThreadExample-7cec5e.o
      "boost::thread::start_thread_noexcept()", referenced from:
          boost::thread::start_thread() in simpleThreadExample-7cec5e.o
      "boost::thread::detach()", referenced from:
          boost::thread::~thread() in simpleThreadExample-7cec5e.o
      "typeinfo for boost::detail::thread_data_base", referenced from:
          typeinfo for boost::detail::thread_data<void (*)()> in simpleThreadExample-7cec5e.o
      "vtable for boost::detail::thread_data_base", referenced from:
          boost::detail::thread_data_base::thread_data_base() in simpleThreadExample-7cec5e.o
      NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
    ld: symbol(s) not found for architecture x86_64
    clang: error: linker command failed with exit code 1 (use -v to see invocation)

现在,以下两个程序可以编译并正常运行:

        #include <locale>
        #include <boost/date_time/gregorian/gregorian.hpp>
        #include <boost/date_time/posix_time/posix_time.hpp>

        using namespace std;
        using namespace boost::gregorian;
        using namespace boost::posix_time;

        int main() 
        {

          date today = day_clock::local_day(); 
          cout << today << endl;

        }

        #include <iostream>
        #include <iomanip>
        #include <boost/geometry.hpp>
        #include <boost/geometry/geometries/point.hpp>

        using namespace std;

        int main()
        {

            //point_type p = boost::geometry::make<point_type>(1, 2, 3);
            //std::cout << boost::geometry::dsv(p) << std::endl;
            //return 0;


            boost::geometry::model::point<int, 3, boost::geometry::cs::cartesian> p;
            boost::geometry::assign_values(p,1, 2, 3);

            boost::geometry::model::point<int, 3, boost::geometry::cs::cartesian> p2;

            p2 = p;

            cout << boost::geometry::dsv(p) << endl;

            cout << boost::geometry::dsv(p2) << endl;

            return 0;
        }

而且,当我编译时,我会:

g++ -std=c++11 -I /usr/local/boost_1_57_0 <nameOfProgram.cpp>

因此,我想知道为什么在我唯一要更改的是程序名的情况下,为什么线程程序无法编译而其他两个线程却不能编译?

如果有帮助,我正在使用Boost 1.57,它的路径是:

 /usr/local/Cellar/boost/1.57.0

头文件的路径为:

/usr/local/Cellar/boost/1.57.0/include/boost

如果有人可以提供一些见识,那将是非常棒的。谢谢!

巴里

您还必须链接到boost库:

-lboost_thread

可能还有-L路径的附加参数,也可能是标准-lpthread

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

架构x86_64的未定义符号:OS X,Boost Log,CMake

Boost.MPI 为架构 x86_64 提供未定义符号

如何修复架构x86_64,Boost Asio 1.58的未定义符号

Mac上的架构x86_64 C ++的未定义符号

使用Json-C的架构x86_64的未定义符号

Kotlin Multiplatform - Objective-C 互操作性架构问题 x86_64 架构的未定义符号

使用C ++链接列表创建时编译错误。架构x86_64的未定义符号:

osx-体系结构x86_64的boost和python未定义符号

boost :: filesystem体系结构x86_64的未定义符号

体系结构x86_64(c)的未定义符号

C中体系结构x86_64的未定义符号

编译C程序中体系结构x86_64的未定义符号

C ++体系结构x86_64的未定义符号

如何在C中修复“体系结构x86_64的未定义符号”?

C ++使用指针时获取体系结构x86_64的未定义符号

体系结构x86_64的未定义符号:用C ++编译

使用g ++编译C ++程序的体系结构x86_64的未定义符号

体系结构x86_64的未定义符号:在Xcode 8中调用C ++函数时

使用Catalina C ++进行卷曲失败,并获得“体系结构x86_64的未定义符号”

C ++:使用“ std”时出现“体系结构x86_64的未定义符号”错误

C ++中的“体系结构x86_64的未定义符号:”错误的原因是什么?

在C语言中,“体系结构x86_64的未定义符号:”是什么意思?

Xcode C ++ ::架构x86_64的重复符号

C:架构x86_64的重复符号

架构x86_64抖动的未定义符号

架构x86_64的未定义符号:“ _fcloseall”

ProgressHUD:架构 x86_64 的未定义符号:

错误架构x86_64的未定义符号:

用C语言定义一个`extern`变量,xcode发送一个x86_64体系结构的未定义符号