如何使用铛链接Boost库1.54? [英] How to link boost library 1.54 using clang?

查看:201
本文介绍了如何使用铛链接Boost库1.54?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Mac使用铛安装提振。

I have installed boost in my mac using clang.

Include =  /usr/local/include/boost-1_54/  
Lib    = /usr/local/lib/ 

(libboost_atomic - 铛 - darwin42-MT-1_54.a,libboost_math_c99f - 铛 - darwin42-MT-1_54.dylib)

( libboost_atomic-clang-darwin42-mt-1_54.a, libboost_math_c99f-clang-darwin42-mt-1_54.dylib)

然后我想测试如果安装不在了正确与否。我尝试编译一个简单的code这使用boost ::正则表达式。

and then I wanted to test if the installation is gone right or not. I try to compile a simple code which use boost::regex.

$$ clang++ -I /usr/local/include/boost-1_54/ -L /usr/local/lib/ -o regex test_regex.cpp

它给出​​了错误说

It gives error saying

 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)

我记得使用-libregex或东西,而使用gcc来编译简单的提升计划。我已经尝试了所有的组合,但它仍然给错误说(我的意思是-libboost_regex-MT,libboost_atomic - 铛 - darwin42-MT-1_54.a,..)

I remember using -libregex or something while using gcc to compile simple boost program. I have tried all combination but it still gives error saying ( by that I mean -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

谁能帮我怎么能告诉铛使用适当的库函数来正确编译测试?请

Can anyone help how can I tell clang to use the proper library function to compile the test correctly?Please

推荐答案

现在我作为一个初学者OSX程序员也有这个问题,而神秘的1号线的回答以下没有帮助我。

Now I as a beginner osx programmer also had this problem, and the cryptic 1 line below the answer did not help me.

几个令人沮丧小时,安装和重新编译升压后,我终于找到了如何做到这一点。

After several frustrating hours and installing and recompiling boost I finally found out how to do this.

我使用了一个名为MacPorts的非常有用的程序,它可以被发现在安装Boost库//www.macports .ORG /

I installed boost libraries using a very helpful program called MacPorts, which can be found at : http://www.macports.org/

然后命令来获取并安装升压是:sudo的港口安装升压

Then the command to get and install boost is : sudo port install boost

Boost库,然后出现在文件夹中的/ opt / local / lib目录

The boost libraries then appear in the folder /opt/local/lib

要链接添加以下的LD链接你的图书馆的:
-lboost_regex-MT

To link add the following to your librarys in the ld linker : -lboost_regex-mt

注意,实际的文件名是libboost_regex-mt.a的LIB在一开始被省略链接器命令行上,东西扔我,直到我读了手册。

note that the actual filename is libboost_regex-mt.a , the "lib" at the start is omitted on the linker command line, something that threw me until I read the manual page.

如果你这样做,那么升压应该链接和未定义的符号错误应该消失。

If you do this then boost should link and the undefined symbols error should disappear.

我希望这有助于。

这篇关于如何使用铛链接Boost库1.54?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆