mercredi 1 avril 2015

Why does this boost example not link on OS X?

I have a very small example app that builds, links, and runs correctly on Ubuntu. But when I try on OS X, I get link errors I cannot figure out.


Here is my 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 is my 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, it finds Boost version 1.57.0 and AppleClang 5.1.05030040. But when I try to run make I get approximately 250 lines of errors, starting with:



Linking CXX executable myapp
Undefined symbols for 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] and 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

Aucun commentaire:

Enregistrer un commentaire