c++ - Why does this boost example not link on OS X? -
i have small example app builds, links, , runs correctly on ubuntu. when try on os x, link errors cannot figure out.
here cmakelists.txt file:
project ( test c cxx ) cmake_minimum_required ( version 2.8 ) set ( boost_use_static_libs on ) set ( boost_use_multithreaded on ) set ( boost_use_static_runtime on ) find_package ( boost required components regex system date_time ) find_package ( threads required ) include_directories ( after ${boost_include_dir} ) set ( cmake_cxx_flags "${cmake_cxx_flags} -std=c++11 -stdlib=libc++" ) add_executable ( myapp test.cpp ) target_link_libraries ( myapp ${cmake_thread_libs_init} ${boost_libraries} )
here test.cpp file:
#include <boost/regex.hpp> #include <iostream> #include <chrono> int main() { boost::regex e( "he[^ ]{3} " ); if (boost::regex_search( "hello world", e )) { std::cout << "found!" << std::endl; } return 0; }
running cmake ..
works fine, finds boost version 1.57.0 , appleclang 5.1.05030040. when try run make
approximately 250 lines of errors, starting with:
linking cxx executable myapp undefined symbols architecture x86_64: "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)", 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> > >::perl_matcher(char const*, char const*, boost::match_results<char const*, std::__1::allocator<boost::sub_match<char const*> > >&, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags, char const*) in test.cpp.o "boost::re_detail::perl_matcher<char const*, std::__1::allocator<boost::sub_match<char const*> >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::find()", referenced from: bool boost::regex_search<char const*, char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >(char const*, char const*, boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > > const&, boost::regex_constants::_match_flags) in test.cpp.o "std::string::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)
i'm on os x 10.8.5 [mountain lion] , using:
$ clang++ --version apple llvm version 5.1 (clang-503.0.40) (based on llvm 3.4svn) target: x86_64-apple-darwin12.5.0 thread model: posix
edit: asked, here command verbose=1
:
[100%] building cxx object cmakefiles/myapp.dir/test.cpp.o /applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/c++ -std=c++11 -stdlib=libc++ -i/usr/local/include -o cmakefiles/myapp.dir/test.cpp.o -c /users/administrator/tmp/test.cpp linking cxx executable myapp /usr/local/cellar/cmake/3.2.1/bin/cmake -e cmake_link_script cmakefiles/myapp.dir/link.txt --verbose=1 /applications/xcode.app/contents/developer/toolchains/xcodedefault.xctoolchain/usr/bin/c++ -std=c++11 -stdlib=libc++ -wl,-search_paths_first -wl,-headerpad_max_install_names cmakefiles/myapp.dir/test.cpp.o -o myapp /usr/local/lib/libboost_regex.a /usr/local/lib/libboost_system.a /usr/local/lib/libboost_date_time.a undefined symbols architecture x86_64: "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)", referenced from:
i suspect boost libraries compiled libstdc++, , building against libc++.
edit:
to boost use libc++ instead of libstdc++, install with:
brew install boost --c++11
to see if boost linking against libc++ or libstdc++, try this:
otool -l /usr/local/lib/libboost_regex-mt.dylib
Comments
Post a Comment