I have used QuantLib on both Mac OS X and Ubuntu.
The answer SmallChess provided here is a perfect explanation / guide for setting up QuantLib for Xcode. I had QuantLib configured on Xcode as well until I switched to using the Eclipse IDE for C/C++ as I prefer it over Xcode. (I also do work predominantly on Ubuntu now, which means I have to use Eclipse over Xcode).
The advantage here is that Eclipse is compatible on OS X, Linux and Windows allowing for a bit more flexibility. Eclipse also supports multiple languages so it’s a good IDE to learn how to use. You can download the newest Eclipse C/C++ IDE for OS X here: Mac OS X (Cocoa) 64-bit.
The process for setting up QuantLib with Eclipse is similar to Xcode however it may entail more quality time in the UNIX command line (nothin’ wrong with that right?!)
Can i compile and link on the command line?
Yes of course! I enjoy working in the command line and for this reason I often just use Eclipse for developing source code, editing and debugging since it is easier to see what is wrong using an IDE versus all in the CLI.
Once the code has been developed in the IDE, one can just
cdinto the right directory, and then linking QuantLib compile and run it doing
clang++ gaussian1dmodels.cpp -l QuantLib. Note that this command works regardless of IDE, and you can replace
g++ if that is what you use. For running,
./a.out does the job. This gives you the conveinence and clarity of an integrated development environment and the flexibility of the UNIX CLI.
I assume you have already installed QuantLib and your question is more about integrating it with an IDE. If not, it is just a matter of downloading the tar.gz file which you can get here, extracting it with something like
tar xzvf QuantLib-whateverversionyouwant.tar.gz, then go into the QuantLib directory, depending on which version of OS X you're running you will have to do some extra configuring with respect to environment variables and such. There is no point in going into detail regarding this step as all of this is documented well on their OS X docs page. Once you do that you run a
make and a
sudo make install.
If you are curious about what Eclipse looks like compared to Xcode, here's a screenshot:
It is important to remember to link whatever library you're using through the CLI when compiling.
In case you want to just do everything through Eclipse you will have to do the following:
- Putting source code into the right spot: To do this correctly, press file, new, C++ Project, you will then be given the option to select which C++ compiler you wish to use. After this you have several options, you can right click your project, click new, then file and copy & paste an example from their github repository. Or you can go into the terminal, make sure you are in the directory where QuantLib (and the examples) are installed and then enter
cp EquityOption.cpp ~/eclipse-workspace/quantlibtest.cpp/src/. Now this obviously is completely dependent on what you have named your workspace, where stuff was installed, etc however the key command here is
cp and specifying your directory. It is my preference to use the CLI rather than the GUI however both can be done, the CLI is just more intuitive.
- Adding lib paths: Once source code is in the right place, you have to configure the properties of the project. Recall we not only have QuantLib installed but boost as well, we need to add both. Go to the project in Eclipse, go to properties (alt enter does it on Linux), go to C/C++ build, settings, select "all configurations" for the Configuration setting, go to libraries, then add QuantLib and boost_timer. Once these libraries and paths have been added, compilation through Eclipse should work!