簡體   English   中英

用於Boost C ++的體系結構x86_64的未定義符號

[英]Undefined symbols for architecture x86_64 for Boost C++

我試圖為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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM