Boost for Mac安装

来源:互联网 发布:windows官网镜像 编辑:程序博客网 时间:2024/06/05 10:45

最近想用一下boost,由于习惯Mac系统,所以就打算用Xcode+boost写点代码。首先得安装boost, 

安装port或brew,有了它们,安装就简单了,以前我一篇文章介绍了它们的安装与使用。今天我用的是brew, 打开命令行

  1. brew install boost  

1.49版本的boost差不多2百多M,安装好后的目录是/usr/local/Cellar/boost/1.49.0


新建一个工程,选择apple command line的工程模板,然后配置头文件与库的目录,分别是:

/usr/local/Cellar/boost/1.49.0/include

/usr/local/Cellar/boost/1.49.0/lib


写一个hello word, 用到了boost的作用域指针。参看:http://zh.highscore.de/cpp/boost/

  1. #include <iostream>  
  2. #include <boost/scoped_ptr.hpp>  
  3.   
  4.   
  5. int main(int argc, const char * argv[])  
  6. {  
  7.   
  8.     // insert code here...  
  9.     std::cout << "Hello, World!\n";  
  10.     boost::scoped_ptr<int> i(new int);  
  11.     *i = 1;  
  12.     *i.get() = 2;  
  13.     i.reset(new int);  
  14.       
  15.     return 0;  
  16. }  

慢慢进入boost的世界。
0 0