在Linux机器上,我的代码可以成功构建。
但是,在我的Mac上,除非我拿出这部分,否则无法构建相同的命令:
void split_is(const std::string &s, string delim_regex, std::vector<std::string> &elems) {
// Terribly slow and inefficient, sorry. Should probably fix this at some point
boost::algorithm::split_regex(elems, s, regex(delim_regex));
std::vector<std::string> non_zero_elems;
for(int e = 0; e < elems.size(); e++){
if (elems[e].length() > 0){
non_zero_elems.push_back(elems[e]);
}
}
elems = non_zero_elems; }
我使用的命令是:
g++ -lboost_regex -lgurobi_c++ -lgurobi60 -stdlib=libstdc++ -lpthread
-lm -Wall -m64 -fPIE -fexceptions -frounding-math -O2 -I/Library/gurobi604/mac64/include/ -I/usr/local/include/ -L/Library/gurobi604/mac64/lib/ -L/usr/local/lib/ main.cpp tools.cpp treeofdevil.cpp solver.cpp periodicfunction.cpp -o ising.exe /usr/local/lib/libboost_regex.a
有谁知道可能出错的地方?谢谢。
我得到的错误是:
Undefined symbols for architecture x86_64:
"boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >::maybe_assign(boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > > const&)", referenced from:
boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_prefix() in tools-9bd02e.o
boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_match() in tools-9bd02e.o
"boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags)", referenced from:
boost::re_detail::perl_matcher<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::perl_matcher(__gnu_cxx::__normal_iterator<char const*, std::string>, __gnu_cxx::__normal_iterator<char const*, std::string>, boost::match_results<__gnu_cxx::__normal_iterator<char const*, std::string>, std::allocator<boost::sub_match<__gnu_cxx::__normal_iterator<char const*, std::string> > > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags, __gnu_cxx::__normal_iterator<char const*, std::string>) in tools-9bd02e.o
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::compare(char const*) const", referenced from:
unsigned int boost::re_detail::find_sort_syntax<boost::re_detail::cpp_regex_traits_implementation<char>, char>(boost::re_detail::cpp_regex_traits_implementation<char> const*, char*) in libboost_regex.a(instances.o)
char const* boost::re_detail::re_is_set_member<char const*, char, boost::regex_traits<char, boost::cpp_regex_traits<char> >, unsigned int>(char const*, char const*, boost::re_detail::re_set_long<unsigned int> const*, boost::re_detail::regex_data<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, bool) in libboost_regex.a(instances.o)
char* boost::re_detail::re_is_set_member<char*, char, boost::regex_traits<char, boost::cpp_regex_traits<char> >, unsigned int>(char*, char*, boost::re_detail::re_set_long<unsigned int> const*, boost::re_detail::regex_data<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, bool) in libboost_regex.a(instances.o)
"std::__1::__vector_base_common<true>::__throw_length_error() const", referenced from:
void std::__1::vector<boost::re_detail::recursion_info<boost::match_results<char const*, std::__1::allocator<boost::sub_match<char const*> > > >, std::__1::allocator<boost::re_detail::recursion_info<boost::match_results<char const*, std::__1::allocator<boost::sub_match<char const*> > > > > >::__push_back_slow_path<boost::re_detail::recursion_info<boost::match_results<char const*, std::__1::allocator<boost::sub_match<char const*> > > > const>(boost::re_detail::recursion_info<boost::match_results<char const*, std::__1::allocator<boost::sub_match<char const*> > > > const&) in libboost_regex.a(instances.o)
std::__1::vector<boost::sub_match<char const*>, std::__1::allocator<boost::sub_match<char const*> > >::vector(std::__1::vector<boost::sub_match<char const*>, std::__1::allocator<boost::sub_match<char const*> > > const&) in libboost_regex.a(instances.o)
std::__1::vector<boost::sub_match<char const*>, std::__1::allocator<boost::sub_match<char const*> > >::insert(std::__1::__wrap_iter<boost::sub_match<char const*> const*>, unsigned long, boost::sub_match<char const*> const&) in libboost_regex.a(instances.o)
std::__1::enable_if<(__is_forward_iterator<boost::sub_match<char const*>*>::value) && (is_constructible<boost::sub_match<char const*>, std::__1::iterator_traits<boost::sub_match<char const*>*>::reference>::value), void>::type std::__1::vector<boost::sub_match<char const*>, std::__1::allocator<boost::sub_match<char const*> > >::assign<boost::sub_match<char const*>*>(boost::sub_match<char const*>*, boost::sub_match<char const*>*) in libboost_regex.a(instances.o)
std::__1::vector<bool, std::__1::allocator<bool> >::assign(unsigned long, bool const&) in libboost_regex.a(instances.o)
std::__1::vector<bool, std::__1::allocator<bool> >::reserve(unsigned long) in libboost_regex.a(instances.o)
void std::__1::vector<std::__1::pair<bool, boost::re_detail::re_syntax_base*>, std::__1::allocator<std::__1::pair<bool, boost::re_detail::re_syntax_base*> > >::__push_back_slow_path<std::__1::pair<bool, boost::re_detail::re_syntax_base*> const>(std::__1::pair<bool, boost::re_detail::re_syntax_base*> const&) in libboost_regex.a(instances.o)
...
"std::__1::__vector_base_common<true>::__throw_out_of_range() const", referenced from:
boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_open_paren() in libboost_regex.a(instances.o)
boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_perl_extension() in libboost_regex.a(instances.o)
"std::__1::__basic_string_common<true>::__throw_length_error() const", referenced from:
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_collatename(char const*, char const*) const in libboost_regex.a(instances.o)
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_classname_imp(char const*, char const*) const in libboost_regex.a(instances.o)
boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fail(boost::regex_constants::error_type, long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long) in libboost_regex.a(instances.o)
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_classname(char const*, char const*) const in libboost_regex.a(instances.o)
"std::__1::locale::use_facet(std::__1::locale::id&) const", referenced from:
boost::re_detail::cpp_regex_traits_base<char>::imbue(std::__1::locale const&) in libboost_regex.a(instances.o)
boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in libboost_regex.a(instances.o)
boost::shared_ptr<boost::re_detail::cpp_regex_traits_implementation<char> const> boost::re_detail::create_cpp_regex_traits<char>(std::__1::locale const&) in libboost_regex.a(instances.o)
"std::__1::ios_base::getloc() const", referenced from:
boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in libboost_regex.a(instances.o)
"std::logic_error::logic_error(char const*)", referenced from:
boost::match_results<char const*, std::__1::allocator<boost::sub_match<char const*> > >::raise_logic_error() in libboost_regex.a(instances.o)
"std::logic_error::logic_error(char const*)", referenced from:
boost::re_detail::perl_matcher<char const*, std::__1::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::construct_init(boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) in libboost_regex.a(instances.o)
"std::logic_error::logic_error(std::logic_error const&)", referenced from:
void boost::throw_exception<std::invalid_argument>(std::invalid_argument const&) in libboost_regex.a(instances.o)
void boost::throw_exception<std::logic_error>(std::logic_error const&) in libboost_regex.a(instances.o)
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::logic_error> >::rethrow() const in libboost_regex.a(instances.o)
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::logic_error> >::clone_impl(boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::logic_error> > const&, boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::logic_error> >::clone_tag) in libboost_regex.a(instances.o)
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::logic_error> >::clone_impl(boost::exception_detail::error_info_injector<std::logic_error> const&) in libboost_regex.a(instances.o)
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::invalid_argument> >::rethrow() const in libboost_regex.a(instances.o)
boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::invalid_argument> >::clone_impl(boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::invalid_argument> > const&, boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<std::invalid_argument> >::clone_tag) in libboost_regex.a(instances.o)
...
"std::runtime_error::runtime_error(char const*)", referenced from:
boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned long) in libboost_regex.a(instances.o)
"std::runtime_error::runtime_error(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
void boost::re_detail::raise_error<boost::regex_traits_wrapper<boost::regex_traits<char, boost::cpp_regex_traits<char> > > >(boost::regex_traits_wrapper<boost::regex_traits<char, ...
boost::re_detail::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const in libboost_regex.a(instances.o)
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_collatename(char const*, char const*) const in libboost_regex.a(instances.o)
boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::append_set(boost::re_detail::basic_char_set<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, mpl_::bool_<false>*) in libboost_regex.a(instances.o)
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*)", referenced from:
boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fail(boost::regex_constants::error_type, long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long) in libboost_regex.a(instances.o)
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(char const*, unsigned long)", referenced from:
boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fail(boost::regex_constants::error_type, long, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, long) in libboost_regex.a(instances.o)
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::append(unsigned long, char)", referenced from:
boost::re_detail::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const in libboost_regex.a(instances.o)
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::assign(char const*, unsigned long)", referenced from:
boost::re_detail::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const in libboost_regex.a(instances.o)
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::assign(unsigned long, char)", referenced from:
char const* boost::re_detail::re_is_set_member<char const*, char, boost::regex_traits<char, boost::cpp_regex_traits<char> >, unsigned int>(char const*, char const*, boost::re_detail::re_set_long<unsigned int> const*, boost::re_detail::regex_data<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, bool) in libboost_regex.a(instances.o)
char* boost::re_detail::re_is_set_member<char*, char, boost::regex_traits<char, boost::cpp_regex_traits<char> >, unsigned int>(char*, char*, boost::re_detail::re_set_long<unsigned int> const*, boost::re_detail::regex_data<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, bool) in libboost_regex.a(instances.o)
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::insert(std::__1::__wrap_iter<char const*>, char)", referenced from:
boost::re_detail::basic_regex_creator<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::append_set(boost::re_detail::basic_char_set<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, mpl_::bool_<false>*) in libboost_regex.a(instances.o)
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::reserve(unsigned long)", referenced from:
boost::re_detail::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const in libboost_regex.a(instances.o)
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__grow_by(unsigned long, unsigned long, unsigned long, unsigned long, unsigned long, unsigned long)", referenced from:
boost::re_detail::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const in libboost_regex.a(instances.o)
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::basic_string(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&)", referenced from:
boost::re_detail::cpp_regex_traits_implementation<char>::lookup_collatename(char const*, char const*) const in libboost_regex.a(instances.o)
boost::cpp_regex_traits<char>::catalog_name(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) in libboost_regex.a(instances.o)
boost::cpp_regex_traits<char>::get_catalog_name() in libboost_regex.a(instances.o)
boost::re_detail::cpp_regex_traits_implementation<char>::error_string(boost::regex_constants::error_type) const in libboost_regex.a(instances.o)
boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse(char const*, char const*, unsigned int) in libboost_regex.a(instances.o)
boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::fail(boost::regex_constants::error_type, long) in libboost_regex.a(instances.o)
boost::re_detail::basic_regex_parser<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::parse_extended() in libboost_regex.a(instances.o)
...
"std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
boost::re_detail::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const in libboost_regex.a(instances.o)
boost::re_detail::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const in libboost_regex.a(instances.o)
.....const in libboost_regex.a(instances.o)
boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::imbue(std::__1::locale) in libboost_regex.a(instances.o)
boost::cpp_regex_traits<char>::imbue(std::__1::locale) in libboost_regex.a(instances.o)
boost::shared_ptr<boost::re_detail::cpp_regex_traits_implementation<char> const> boost::re_detail::create_cpp_regex_traits<char>(std::__1::locale const&) in libboost_regex.a(instances.o)
boost::object_cache<boost::re_detail::cpp_regex_traits_base<char>, boost::re_detail::cpp_regex_traits_implementation<char> >::do_get(boost::re_detail::cpp_regex_traits_base<char> const&, unsigned long) in libboost_regex.a(instances.o)
unsigned long std::__1::__tree<std::__1::__value_type<boost::re_detail::cpp_regex_traits_base<char>, std::__1::__list_iterator<std::__1::pair<boost::shared_ptr<boost::re_detail::cpp_regex_traits_implementation<char> const>, boost::re_detail::cpp_regex_traits_base<char> const*>, void*> >, std::__1::__map_value_compare<boost::re_detail::cpp_regex_traits_base<char>, std::__1::__value_type<boost::re_detail::cpp_regex_traits_base<char>, std::__1::__list_iterator<std::__1::pair<boost::shared_ptr<boost::re_detail::cpp_regex_traits_implementation<char> const>, boost::re_detail::cpp_regex_traits_base<char> const*>, void*> >, std::__1::less<boost::re_detail::cpp_regex_traits_base<char> >, true>, std::__1::allocator<std::__1::__value_type<boost::re_detail::cpp_regex_traits_base<char>, std::__1::__list_iterator<std::__1::pair<boost::shared_ptr<boost::re_detail::cpp_regex_traits_implementation<char> const>, boost::re_detail::cpp_regex_traits_base<char> const*>, void*> > > >::__erase_unique<boost::re_detail::cpp_regex_traits_base<char> >(boost::re_detail::cpp_regex_traits_base<char> const&) in libboost_regex.a(instances.o)
...
"std::__1::locale::operator=(std::__1::locale const&)", referenced from:
boost::re_detail::cpp_regex_traits_base<char>::imbue(std::__1::locale const&) in libboost_regex.a(instances.o)
boost::shared_ptr<boost::re_detail::cpp_regex_traits_implementation<char> const> boost::re_detail::create_cpp_regex_traits<char>(std::__1::locale const&) in libboost_regex.a(instances.o)
"std::__1::collate<char>::id", referenced from:
boost::re_detail::cpp_regex_traits_base<char>::imbue(std::__1::locale const&) in libboost_regex.a(instances.o)
boost::shared_ptr<boost::re_detail::cpp_regex_traits_implementation<char> const> boost::re_detail::create_cpp_regex_traits<char>(std::__1::locale const&) in libboost_regex.a(instances.o)
"std::__1::ios_base::init(void*)", referenced from:
boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in libboost_regex.a(instances.o)
"std::__1::ios_base::clear(unsigned int)", referenced from:
boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in libboost_regex.a(instances.o)
"std::__1::numpunct<char>::id", referenced from:
boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in libboost_regex.a(instances.o)
"std::__1::basic_ios<char, std::__1::char_traits<char> >::~basic_ios()", referenced from:
boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in libboost_regex.a(instances.o)
"typeinfo for std::__1::basic_streambuf<char, std::__1::char_traits<char> >", referenced from:
typeinfo for boost::re_detail::parser_buf<char, std::__1::char_traits<char> > in libboost_regex.a(instances.o)
"vtable for std::__1::basic_istream<char, std::__1::char_traits<char> >", referenced from:
boost::cpp_regex_traits<char>::toi(char const*&, char const*, int) const in libboost_regex.a(instances.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)
答案 0 :(得分:5)
我怀疑你这里有不止一件事;移动-lboost_regex
应解决其中一些问题。
我怀疑你遇到的主要问题是你已经使用libc ++构建了程序的一部分(可能是boost库),其余部分使用libstdc ++。
您的构建命令显式地显示-stdlib=libstdc++
,但错误消息提到了std::__1::....
,这是libc ++中存在的内容。