我在macos小牛隊中從homebrew安裝了boost 1.55.0。獲取鏈接器異常 - 找不到std :: string :: c_str(),我不明白爲什麼。這可能是自制軟件的問題嗎?我試着直接從boost編譯boost 1.55.0,它甚至不建立在macos上。鏈接器錯誤 - 未定義的符號std :: string :: c_str()常量在macos與libboost_thread?
的代碼這一點:
#include <iostream>
#include <unordered_map>
#include <vector>
#include <boost/thread/tss.hpp>
typedef std::unordered_map<std::string, std::string> StringMap;
static boost::thread_specific_ptr<std::vector<StringMap*>> rlist;
int main()
{
return 0;
}
使用此命令行編譯:
g++ -std=c++11 main.cpp -I/usr/local/include -L/usr/local/lib -lboost_thread -lboost_system -lboost_atomic -lboost_log -lstdc++
拋出此鏈接異常:
Undefined symbols for architecture x86_64:
"std::string::c_str() const", referenced from:
boost::system::system_error::what() const in libboost_thread.a(thread.o)
"std::string::empty() const", referenced from:
boost::system::system_error::what() const in libboost_thread.a(thread.o)
"std::allocator<char>::allocator()", referenced from:
boost::system::system_error::system_error(boost::system::error_code, char const*) in libboost_thread.a(thread.o)
boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system.a(error_code.o)
"std::allocator<char>::~allocator()", referenced from:
boost::system::system_error::system_error(boost::system::error_code, char const*) in libboost_thread.a(thread.o)
boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system.a(error_code.o)
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
boost::system::system_error::system_error(boost::system::error_code, char const*) in libboost_thread.a(thread.o)
boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system.a(error_code.o)
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(std::string const&)", referenced from:
boost::thread_exception::thread_exception(boost::thread_exception const&) in libboost_thread.a(thread.o)
boost::condition_error::condition_error(boost::condition_error const&) in libboost_thread.a(thread.o)
boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system.a(error_code.o)
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string()", referenced from:
boost::system::system_error::system_error(boost::system::error_code, char const*) in libboost_thread.a(thread.o)
boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system.a(error_code.o)
"std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()", referenced from:
boost::system::system_error::what() const in libboost_thread.a(thread.o)
boost::system::system_error::~system_error() in libboost_thread.a(thread.o)
boost::system::system_error::~system_error() in libboost_thread.a(thread.o)
boost::thread_exception::~thread_exception() in libboost_thread.a(thread.o)
boost::thread_exception::~thread_exception() in libboost_thread.a(thread.o)
boost::thread_resource_error::~thread_resource_error() in libboost_thread.a(thread.o)
boost::thread_resource_error::~thread_resource_error() in libboost_thread.a(thread.o)
...
"std::string::operator=(char const*)", referenced from:
boost::system::system_error::what() const in libboost_thread.a(thread.o)
boost::system::(anonymous namespace)::generic_error_category::message(int) const in libboost_system.a(error_code.o)
"std::string::operator+=(char const*)", referenced from:
boost::system::system_error::what() const in libboost_thread.a(thread.o)
"std::string::operator+=(std::string const&)", referenced from:
boost::system::system_error::what() const in libboost_thread.a(thread.o)
"std::runtime_error::runtime_error(std::string const&)", referenced from:
boost::system::system_error::system_error(boost::system::error_code, char const*) in libboost_thread.a(thread.o)
"std::_Rb_tree_decrement(std::_Rb_tree_node_base*)", referenced from:
std::_Rb_tree<void const*, std::pair<void const* const, boost::detail::tss_data_node>, std::_Select1st<std::pair<void const* const, boost::detail::tss_data_node> >, std::less<void const*>, std::allocator<std::pair<void const* const, boost::detail::tss_data_node> > >::_M_insert_unique(std::pair<void const* const, boost::detail::tss_data_node> const&) in libboost_thread.a(thread.o)
"std::_Rb_tree_increment(std::_Rb_tree_node_base*)", referenced from:
_tls_destructor in libboost_thread.a(thread.o)
std::_Rb_tree<void const*, std::pair<void const* const, boost::detail::tss_data_node>, std::_Select1st<std::pair<void const* const, boost::detail::tss_data_node> >, std::less<void const*>, std::allocator<std::pair<void const* const, boost::detail::tss_data_node> > >::erase(std::_Rb_tree_iterator<std::pair<void const* const, boost::detail::tss_data_node> >, std::_Rb_tree_iterator<std::pair<void const* const, boost::detail::tss_data_node> >) in libboost_thread.a(thread.o)
"std::__throw_length_error(char const*)", referenced from:
std::vector<std::pair<boost::condition_variable*, boost::mutex*>, std::allocator<std::pair<boost::condition_variable*, boost::mutex*> > >::_M_insert_aux(__gnu_cxx::__normal_iterator<std::pair<boost::condition_variable*, boost::mutex*>*, std::vector<std::pair<boost::condition_variable*, boost::mutex*>, std::allocator<std::pair<boost::condition_variable*, boost::mutex*> > > >, std::pair<boost::condition_variable*, boost::mutex*> const&) in libboost_thread.a(thread.o)
"std::_Rb_tree_rebalance_for_erase(std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)", referenced from:
_tls_destructor in libboost_thread.a(thread.o)
std::_Rb_tree<void const*, std::pair<void const* const, boost::detail::tss_data_node>, std::_Select1st<std::pair<void const* const, boost::detail::tss_data_node> >, std::less<void const*>, std::allocator<std::pair<void const* const, boost::detail::tss_data_node> > >::erase(std::_Rb_tree_iterator<std::pair<void const* const, boost::detail::tss_data_node> >, std::_Rb_tree_iterator<std::pair<void const* const, boost::detail::tss_data_node> >) in libboost_thread.a(thread.o)
"std::_Rb_tree_insert_and_rebalance(bool, std::_Rb_tree_node_base*, std::_Rb_tree_node_base*, std::_Rb_tree_node_base&)", referenced from:
std::_Rb_tree<void const*, std::pair<void const* const, boost::detail::tss_data_node>, std::_Select1st<std::pair<void const* const, boost::detail::tss_data_node> >, std::less<void const*>, std::allocator<std::pair<void const* const, boost::detail::tss_data_node> > >::_M_insert_unique(std::pair<void const* const, boost::detail::tss_data_node> const&) in libboost_thread.a(thread.o)
l
是什麼'G ++ -v'給你? –