Wednesday, August 15, 2012

Using Boost with XCode First Project

This Project involves setting up XCode to use boost. It's very simple, it does not involve using compiled libraries.

Assuming that you have followed the steps on the previous post on Installing Boost on OSX and have copied the libraries /usr/local/include/boost

Note: If you have used MacPorts your libraries are stored in /opt/local/include/boost

1. Open XCode and create a new C++ Project
2. Click on the project to open the settings and search for a parameter called "Header Search Paths"
change it to /usr/local/include. Boost libraries should be copied here.

Boost XCode 4.4 Setup
That's really it. You don't have to add anything to the target or give XCode a library search path. Make sure "Always Search User Paths" is set to "No" and you are good.

Boost First Program 
 #include <boost/array.hpp>  
 #include <iostream>  
 int main()  
 {  
   boost::array<int, 10>myarray;   
   myarray.fill(2);  
   for (int i=0; i<10; i++) {  
     std::cout << myarray.at(i) << std::endl;  
   }  
   return 0;  
 }  

First Boost Program Download


 

No comments:

Post a Comment