1
$\begingroup$

What is the best way to compile and link QuantLib 1.9 on Mac OS X?

I have Xcode installed and understand an #include may work, if create a new QuantLib main(), but never used this IDE before.

Can i compile and link on the command line? I have latest OS X 10.12 so should i use stdlib=libc++ or =libstdc++?

I get error that --with-boost are unrecognised options. Boost is installed in opt/local/lib and opt/local/install (i think - the files exist but any way to check this? How do i test and configure PATHS)

Overall error is C compiler cannot create executables...

./configure --with-boost-include=/opt/local/include/ \
            --with-boost-lib=/opt/local/lib/ --prefix=/opt/local/ \
            CXXFLAGS='-O2 -stdlib=libc++ -mmacosx-version-min=10.6' \
            LDFLAGS='-stdlib=libc++ -mmacosx-version-min=10.6'
$\endgroup$
6
$\begingroup$

I use Xcode for QuantLib. It works great. To compile the project, just put all the source files into the Xcode project like:

enter image description here

That's the C++ compiler I use:

enter image description here

That's how I configure my header files. You will only need boost in my screenshot. You will also need to tell Xcode where to find the QuantLib header files. The other paths are for my own code.

enter image description here

I then created a new source file with the main:

int main(int argc, char ** argv)

Remember add #include <ql/quantlib.hpp> in your main file.

$\endgroup$
  • $\begingroup$ Could you show the full IDE code file/window? @smallchess $\endgroup$ – rrg Apr 2 '18 at 15:00
3
$\begingroup$

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 clang++ with 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: Eclipse

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:

  1. 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. choose your C compiler 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.
  2. 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!
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.