我已经使用 clang 在我的 mac 中安装了 boost。
Include = /usr/local/include/boost-1_54/
Lib = /usr/local/lib/
(libboost_atomic-clang-darwin42-mt-1_54.a, libboost_math_c99f-clang-darwin42-mt-1_54.dylib)
然后我想测试安装是否正确。我尝试编译一个使用 boost::regex 的简单代码。
$$ clang++ -I /usr/local/include/boost-1_54/ -L /usr/local/lib/ -o regex test_regex.cpp
它给出了错误的说法
Undefined symbols for architecture x86_64:
"boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::do_assign(char const*, char const*, unsigned int)", referenced from:
boost::basic_regex<char, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::assign(char const*, char const*, unsigned int) in test_regex-qSWMLF.o
"boost::re_detail::get_mem_block()", referenced from:
boost::re_detail::perl_matcher<std::__1::__wrap_iter<char const*>, std::__1::allocator<boost::sub_match<std::__1::__wrap_iter<char const*> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::extend_stack() in test_regex-qSWMLF.o
boost::re_detail::save_state_init::save_state_init(boost::re_detail::saved_state**, boost::re_detail::saved_state**) in test_regex-qSWMLF.o
"boost::re_detail::put_mem_block(void*)", referenced from:
boost::re_detail::save_state_init::~save_state_init() in test_regex-qSWMLF.o
boost::re_detail::perl_matcher<std::__1::__wrap_iter<char const*>, std::__1::allocator<boost::sub_match<std::__1::__wrap_iter<char const*> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::unwind_extra_block(bool) in test_regex-qSWMLF.o
"boost::re_detail::verify_options(unsigned int, boost::regex_constants::_match_flags)", referenced from:
boost::re_detail::perl_matcher<std::__1::__wrap_iter<char const*>, std::__1::allocator<boost::sub_match<std::__1::__wrap_iter<char const*> > >, boost::regex_traits<char, boost::cpp_regex_traits<char> > >::match_imp() in test_regex-qSWMLF.o
"boost::re_detail::raise_runtime_error(std::runtime_error 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::cpp_regex_traits<char> > > const&, boost::regex_constants::error_type) in test_regex-qSWMLF.o
"boost::re_detail::get_default_error_string(boost::regex_constants::error_type)", referenced from:
boost::re_detail::cpp_regex_traits_implementation<char>::error_string(boost::regex_constants::error_type) const in test_regex-qSWMLF.o
"boost::re_detail::cpp_regex_traits_implementation<char>::transform_primary(char const*, char const*) const", referenced from:
boost::cpp_regex_traits<char>::transform_primary(char const*, char const*) const in test_regex-qSWMLF.o
"boost::re_detail::cpp_regex_traits_implementation<char>::transform(char const*, char const*) const", referenced from:
boost::cpp_regex_traits<char>::transform(char const*, char const*) const in test_regex-qSWMLF.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我记得在使用 gcc 编译简单的 boost 程序时使用了 -libregex 或其他东西。我已经尝试了所有组合,但它仍然给出错误提示(我的意思是 -libboost_regex-mt,libboost_atomic-clang-darwin42-mt-1_54.a ,..)
$$ clang++ -I /usr/local/include/boost-1_54/ -L /usr/local/lib/ -o regex test_regex.cpp -libboost_regex
ld: library not found for -libregex
谁能帮助我如何告诉 clang 使用正确的库函数来正确编译测试?请