|
From: <mat...@gm...> - 2021-11-17 21:26:57
|
Hello Christian,
Coincidentally I tried the same thing yesterday, also on 1.24.
And I, too, chose to give MSYS2 a try because with the scripting for GNU autotools it is (ostensibly) the easier approach when compared to MSVC.
By the way, looking at your command for building QuantLib, I am intrigued by the library directory "boost_1_77_0/lib64-msvc-14.1". Is it possible to link QuantLib on MSYS2 with boost binaries seemingly compiled on MSVC?
In my trial run, I just installed boost via pacman.
The ql Makefile was generated with the following settings:
./configure --enable-openmp --enable-error-functions --enable-error-lines --enable-std-classes --enable-thread-safe-observer-pattern --enable-thread-safe-singleton-init --disable-benchmark --disable-examples --with-boost-lib=/mingw64/lib --with-boost-include=/mingw64/include --prefix=$HOME/ql_124
Some remarks:
- I set the thread-safe switches on a hunch that it would be the better choice when using QuantLib from Java.
- Could not find an option to also disable unit tests together with benchmark and examples. I hacked them out of the config, because boost unit test failed linking and I did not care enough to try and fix this. Examples were built, curiously, despite the switch.
- Build takes quite a long time (16 core / 32 thread AMD Zen2 machine, using make -j 32).
- Only static library is built, even though the settings should enable both static and shared library builds.
Now the JNI bindings:
./configure --prefix=$HOME/ql_124 --disable-python --disable-csharp --disable-r --enable-java-autocloseable include=$SCOOP_APPS/openjdk11/11.0.2-9/include --with-jdk-system-include=$SCOOP_APPS/openjdk11/11.0.2-9/include/win32 CXXFLAGS="-I$HOME/ql_124/include -I/mingw64/include"
Some remarks:
- Not sure whether the AutoClosable actually works. In the end, I removed that flag and only use finalize. Wrapping lots of stuff in try-with-resources or similar also seems a bit annoying in the first place.
- Without further adjustment, building the wrapper will result in an error ("object file has too many sections"). Using -O3 as additional CXX flag helps here as might -mbig-obj.
No matter what small tweaking to compiler options I applied, linking always yielded the errors you likely encountered as well. A random pick:
undefined reference to `construction vtable for QuantLib::InterpolatedForwardCurve<QuantLib::BackwardFlat>-in-QuantLib::PiecewiseYieldCurve<QuantLib::ForwardRate, QuantLib::BackwardFlat, QuantLib::IterativeBootstrap>'
I really wonder what is causing this. Looks like some missing implementation for virtual functions?
For now, I gave up on this and compiled everything with MSVC (using cmake, adjusting its options according to the configure flags above, i.e. with thread safe observer "ON" etc).
To build the JNI:
mkdir org\quantlib
swig -DJAVA_AUTOLOAD -DJAVA_FINALIZER -java -c++ -outdir org\quantlib -package org.quantlib -o quantlib_wrap.cpp ..\SWIG\quantlib.i
cl /bigobj /O2 /EHsc /I%SCOOP_APPS%\openjdk11\11.0.2-9\include /I%SCOOP_APPS%\openjdk11\11.0.2-9\include\win32 /IE:\quantlib_1_24\x64-Release\include /I%BOOST_ROOT% /D_USRDLL /D_WINDLL quantlib_wrap.cpp /LD /FeQuantLibJNI.dll /link /LIBPATH:E:\quantlib_1_24\x64-Release\lib /LIBPATH:%BOOST_ROOT%\lib64-msvc-14.2
This worked fine and survived some tests so far.
Maybe you can consider using MSVC as well. But if you do find out how to fix these linker errors, I am curious to hear about it.
Best regards,
Matthias
-----Original Message-----
From: ara...@gm... <ara...@gm...>
Sent: Tuesday, 16 November, 2021 17:01
To: qua...@li...
Subject: [Quantlib-users] Building QuantLib-SWIG for Java under Windows (with MSYS2) fails with "undefined reference to vtable for XYZ"
Hi all,
Thanks for taking the time to read this.
I'm trying to build QuantLib-SWIG for Java under Windows. Instead of Visual Studio I'm using MSYS2 (which is based on Cygwin) for building.
The make command compiles the target quantlib_wrap.o successfully but then fails at the target libQuantLibJNI.so with a ton of error messages like this one:
C:/Users/christian/coding/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/11.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe:
quantlib_wrap.o:quantlib_wrap.:(.text$_ZN5boost10shared_ptrIN8QuantLib14SwapRateHelperEEC1IS2_EEPT_[_ZN5boost10shared_ptrIN8QuantLib14SwapRateHelperEEC1IS2_EEPT_]+0x2f):
undefined reference to `vtable for boost::detail::sp_counted_impl_p<QuantLib::SwapRateHelper>'
The versions are:
QuantLib 1.24
QuantLib-SWIG 1.24
Boost 1.77.0 (pre-compiled binaries)
I ran the build of QuantLib-SWIG with the following commands and parameters:
$ ./configure --with-jdk-include="/c/Users/christian/coding/jdk-15/include" --with-jdk-system-include="/c/Users/christian/coding/jdk-15/include/win32"
$ make -C Java
The failing build step is: g++ -g -O2 -shared quantlib_wrap.o -o libQuantLibJNI.so `quantlib-config --libs` The command quantlib-config --libs gives: -L/mingw64/lib -L/c/Users/christian/coding/boost_1_77_0/lib64-msvc-14.1 -lQuantLib The directory /mingw64/lib contains the previously compiled files libQuantLib.a and libQuantLib.la
The build of QuantLib itself was successful. I ran it with the following commands and parameters:
$ ./configure --enable-intraday --with-boost-lib=/c/Users/christian/coding/boost_1_77_0/lib64-msvc-14.1 --with-boost-include=/c/Users/christian/coding/boost_1_77_0
$ make
$ make install
Any ideas would be highly appreciated.
Regards,
Christian
_______________________________________________
QuantLib-users mailing list
Qua...@li...
https://lists.sourceforge.net/lists/listinfo/quantlib-users
|