Problem building QuantLib C# wrapper on Linux

Issue

I have downloaded Quantlib-1.21 and QuantLib-SWIG-1.21 from github, followed the build instructions for Linux without making any changes. The library gets built, it gets installed in /usr/local/lib, the SWIG wrappers are built and compiled, without errors. When I try to run the BermudanSwaption example, with:

dotnet run --project examples/BermudanSwaption/BermudanSwaption.csproj

I get an error along the lines of:

QuantLib.NQuantLibcPINVOKE' threw an exception
System.DllNotFoundException: Unable to load shared library 'NQuantLibc' or one of its dependencies.
libNQuantLibc: cannot open shared object file: No such file or directory

Copying the libNQuantLibc.so file to the same directory as the executable does not seem to work either. Tried running ldconfig as sudo to refresh the linker cache, but it didn’t help.

Any suggestions are welcome.

Solution

I just want to report I was able to fix the problem in case it is useful for somebody else. The issue is that quantlib-config is not in the PATH. So when the wrapper gets compiled, this statement:

g++ -c -fpic -g -O2 cpp/quantlib_wrap.cpp -o cpp/quantlib_wrap.o quantlib-config --cflags

gives the message:

bash: quantlib-config: command not found

but otherwise continues to compile and build the wrapper object. Downstream, when you try to run any executable that uses the NQuantLibc.so library, the DllImport command will fail and say it cannot be found.

I was able to get the c# examples to work by running this before compiling the wrapper:

export PATH = /home/QuantLib:$PATH

It’s able to find quantlib-config and the compilation happens as it was intended. After this, running

make check-local

gives the expected results. Perhaps the QuantLib Cmake or Makefile files need to be updated to add the location of quantlib-config to the PATH?

Answered By – Eduardo

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published