quantlib multithreading/enable-sessions build error on Linux - quantlib

Getting below errors after compiling quantlib 1.9.2 with boost 1.5.4 on Fedora 20 with enable-sessions flag, and running one of the examples, any ideas?
cd QuantLib-1.9.2/
nohup ./configure --enable-sessions --enable-thread-safe-observer-pattern &
tail -f nohup.out
nohup make &
tail -f nohup.out
cp ql/.libs/libQuantLib.so.0.0.0 /lib64/libQuantLib.so
cp ql/.libs/libQuantLib.so.0.0.0 /lib64/libQuantLib.so.0
cd Examples/BermudanSwaption
g++ BermudanSwaption.cpp -o BermudanSwaption -lQuantLib
/usr/lib/gcc/x86_64-redhat-linux/4.8.3/../../../../lib64/libQuantLib.so:
undefined reference to `pthread_mutexattr_destroy'
undefined reference to `QuantLib::sessionId()'
undefined reference to `pthread_mutexattr_init'
undefined reference to `boost::system::system_category()'
undefined reference to `pthread_mutexattr_settype'
undefined reference to `boost::system::generic_category()'
collect2: error: ld returned 1 exit status
Note: Im trying to enable sessions since getting segfault when quantlib is used in multi-threaded client application

answering my own question
1) the pthread and boost_system error disappeared after adding -lboost_system flag to compiler command line:
g++ BermudanSwaption.cpp -o BermudanSwaption -lQuantLib -lboost_system
this helped: undefined reference to boost::system::system_category() when compiling
2) to solve sessionId error I added sessionId function in BermudanSwaption.cpp as suggested here under QL_ENABLE_SESSIONS: https://github.com/lballabio/QuantLib/blob/master/ql/userconfig.hpp
"You will have to provide and link with the library a sessionId()
function in namespace QuantLib, returning a different session id
for each session"
after I commented out #if defined(QL_ENABLE_SESSIONS) in BermudanSwaption.cpp it compiled without errors:
//#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {
Integer sessionId() { return 0; }
}
//#endif

Related

Undefined Reference to `SDL2_Init` with LD when G++ is not giving an error

(FYI Yes I do know that a similar question exists, But I have already tried all the answers.)
I'm trying to setup SDL2 with MinGW and I have everything set up beside one thing. Whenever I try to compile G++ gives no errors but then LD gives me a: undefined reference to SDL_Init Error.
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\AppData\Local\Temp\cc28dE2R.o: in function `SDL_main':
C:\Users\user\Documents\SDL2/src/main.cpp:11: undefined reference to `SDL_Init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\Documents\SDL2/src/main.cpp:14: undefined reference to `SDL_GetError'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\Documents\SDL2/src/main.cpp:18: undefined reference to `IMG_Init'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: C:\Users\user\Documents\SDL2/src/main.cpp:20: undefined reference to `SDL_GetError'
c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../../mingw32/bin/ld.exe: c:/mingw/bin/../lib/gcc/mingw32/9.2.0/../../../libmingw32.a(main.o):(.text.startup+0xc0): undefined reference to `WinMain#16'
collect2.exe: error: ld returned 1 exit status
The terminal process "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe -Command C:\MinGW\bin\g++.exe -g src\*.cpp -o build\game.exe -ID:C:\MinGW\include -LD:C:\MinGW\lib -mwindows -lmingw32 -lSDL2main -lSDL2_image -lSDL2" terminated with exit code: 1.
I have tried to move the args around. doing -mwindows, adding -lmingw32. I still keep getting the same errors.. I was able to fix the WinMain Error.. But everything else I couldn't fix.
The command I'm Running to compile:
C:\MinGW\bin\g++.exe -g src\*.cpp -o build\game.exe -ID:C:\MinGW\include -LD:C:\MinGW\lib -mwindows -lSDL2main -lSDL2_image -lSDL2
If i could get any help that would be amazing
The common cause of mysterious undefined reference errors on MinGW is using libraries compiled for x64 with an x32 compiler, or vice versa. SDL ships both x32 and x64 ones, try the other ones.
I was able to fix the WinMain Error
Be aware that the intended way of fixing undefined reference to WinMain#16 is not adding #define SDL_MAIN_HANDLED and not doing #undef main. Once you get the right libraries (see the first paragraph), the error should disappear by itself.
Make sure you use int main(int, char**) (and not int main() nor void main()), otherwise it won't work.
-ID:C:\MinGW\include -LD:C:\MinGW\lib
You shouldn't need those flags. Those directories will be searched automatically.
Since you didn't specify any other directories, I assume you placed the SDL files directly into the compiler directories, which isn't a good practice, IMO.
I assume D:C: a typo?
-mwindows
The only purpose of this flag (that I know of) is to prevent your app from automatically opening a terminal window for itself, for release builds.

Undefined reference to nlopt_... symbols

I am fairly new to Fortran and this may sound like a silly question. I encounter an error when compiling the Fortran code that is posted as an example in the NLOPT Wiki.
I compile in Ubuntu 18.04 LTS using the following command:
gfortran example-nlopt.f90 -o example-nlopt -I/usr/local/include/
The following error is produced in the terminal:
/tmp/ccbAim6b.o: In function `MAIN__':
example-nlopt.f90:(.text+0x26): undefined reference to `nlo_create_'
example-nlopt.f90:(.text+0x42): undefined reference to `nlo_get_lower_bounds_'
example-nlopt.f90:(.text+0x67): undefined reference to `nlo_set_lower_bounds_'
example-nlopt.f90:(.text+0x8a): undefined reference to `nlo_set_min_objective_'
example-nlopt.f90:(.text+0xca): undefined reference to `nlo_add_inequality_constraint_'
example-nlopt.f90:(.text+0x10e): undefined reference to `nlo_add_inequality_constraint_'
example-nlopt.f90:(.text+0x12d): undefined reference to `nlo_set_xtol_rel_'
example-nlopt.f90:(.text+0x164): undefined reference to `nlo_optimize_'
example-nlopt.f90:(.text+0x305): undefined reference to `nlo_destroy_'
collect2: error: ld returned 1 exit status
Based on what I saw in nlopt's documentation (https://nlopt.readthedocs.io/en/latest/NLopt_Installation/#changing-the-installation-directory) it looks like you just need to specify the library to link against. Maybe try this:
gfortran -I/usr/local/include/ -L/usr/local/lib example-nlopt.f90 -o example-nlopt -lnlopt -lm
This assumes you have the libnlopt.so in /usr/local/lib, if not then point to its location with the -L option.

g++ building c++ program with boost dependencies

I want to compile and run a simple c++ websocket application with g++ on windows.
Boost was installed like this:
./bootstrap.bat mingw
./b2.exe install --prefix=C:/boostLibs toolset=gcc
My c++ includes look like this:
#include <websocketpp/config/asio_no_tls.hpp>
#include <websocketpp/server.hpp>
#include <iostream>
This websocket sample was provided by https://github.com/zaphoyd/websocketpp
In order to build the project I issue this command:
g++ -Wno-deprecated -I ./cppServer/libs/ -I C:\boostLibs\include\boost-1_55 -L C:\boostLibs\lib -g ./cppServer/server.cpp -lboost_system
Which leeds me to this error message:
c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -lboost_system
collect2.exe: error: ld returned 1 exit status
If I try to build without -lboost_system, I get a very long exception, starting with:
C:/boostLibs/include/boost-1_55/boost/system/error_code.hpp:222: undefined reference to boost::system::generic_category()'
C:/boostLibs/include/boost-1_55/boost/system/error_code.hpp:223: undefined reference toboost::system::generic_category()'
C:/boostLibs/include/boost-1_55/boost/system/error_code.hpp:224: undefined reference to boost::system::system_category()'
C:\Users\JOHANN~1.HAS\AppData\Local\Temp\ccpKMWTH.o: In functionZN5boost6system10error_codeC1Ev':
C:/boostLibs/include/boost-1_55/boost/system/error_code.hpp:323: undefined reference to boost::system::system_category()'
C:\Users\JOHANN~1.HAS\AppData\Local\Temp\ccpKMWTH.o: In functionZN5boost6system4errc20make_error_conditionENS1_6errc_tE':
C:/boostLibs/include/boost-1_55/boost/system/error_code.hpp:488: undefined reference to boost::system::generic_category()'
C:\Users\JOHANN~1.HAS\AppData\Local\Temp\ccpKMWTH.o: In functionZN5boost16thread_exceptionC2EiPKc'
So what am I missing? I can't figure it out right now.
Link to boost_system as -lboost_system-mgw63-mt-1_55, because this is what those files are called. See boost library naming for more details.
When you build boost you may like to specify --layout=system to b2.exe so that your files do not have that -mgw63-mt-1_55 in the filename and then just use -lboost_system when linking against it.

Boost "undefined reference" errors even with -lboost_thread

I'm getting some strange compiler/linker errors when trying to use boost::shared_mutex. I'm using boost v1.61 on a VM running 32-bit rhel 6.2.
Code that causes error:
hpp file:
#include <boost/thread/shared_mutex.hpp>
class SharedData
{
public:
SharedData();
~SharedData();
void packMessage(std::shared_ptr<Message> s);
private:
// mutex that allows multiple read, single write protection
boost::shared_mutex m_sharedMutex;
};
cpp file:
void SharedData::packMessage(std::shared_ptr<Message> s)
{
// get shared read access
boost::shared_lock<boost::shared_mutex> lock(m_sharedMutex); // <- this line causes the errors
// read stuff here
}
make output:
CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o: In function `boost::detail::interruption_checker::interruption_checker(pthread_mutex_t*, pthread_cond_t*)':
/usr/local/include/boost/thread/pthread/thread_data.hpp:195: undefined reference to `boost::detail::get_current_thread_data()'
CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o: In function `boost::condition_variable::wait(boost::unique_lock<boost::mutex>&)':
/usr/local/include/boost/thread/pthread/condition_variable.hpp:81: undefined reference to `boost::this_thread::interruption_point()'
CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o: In function `boost::shared_mutex::lock_shared()':
/usr/local/include/boost/thread/pthread/shared_mutex.hpp:186: undefined reference to `boost::this_thread::disable_interruption::disable_interruption()'
/usr/local/include/boost/thread/pthread/shared_mutex.hpp:193: undefined reference to `boost::this_thread::disable_interruption::~disable_interruption()'
/usr/local/include/boost/thread/pthread/shared_mutex.hpp:193: undefined reference to `boost::this_thread::disable_interruption::~disable_interruption()'
collect2: error: ld returned 1 exit status
make[2]: *** [bin/tester] Error 1
Everywhere I've searched has said that these errors mean I need to link the boost_thread library, which I've done in my cmake file (boost_system is included for other code in this same project):
target_link_libraries(${BINARY_NAME} boost_thread boost_system)
But the errors persist.
Originally I was using the boost 1.41 libraries that were already installed on my machine. When I hit these errors I ran yum remove boost-devel and then manually installed boost 1.61 to see if that would correct the errors. Is there something extra I needed to add to the ./bootstrap.sh or ./b2 install commands? I can see libboost_thread.a in /usr/local/lib, so I assumed that meant the thread library was built correctly.
Any thoughts on what is causing these errors? Thanks!
Edit:
Cmake's log didn't have anything useful I could see, but make VERBOSE=1 gives the following output:
cd /home/craig/dev/myProject/build/test && /usr/bin/cmake -E cmake_link_script CMakeFiles/tester.dir/link.txt --verbose=1
/opt/rh/devtoolset-2/root/usr/bin/c++ -std=c++11 -ggdb -Wall -Werror -fprofile-arcs -ftest-coverage -fPIC -O0 -pedantic -Wl,--export-dynamic CMakeFiles/tester.dir/utilities/googletest/googletest/src/gtest-all.cc.o CMakeFiles/tester.dir/tester.cpp.o CMakeFiles/tester.dir/SharedData/testSharedData.cpp.o CMakeFiles/tester.dir/Common/testFifo.cpp.o CMakeFiles/tester.dir/Common/testCsu.cpp.o CMakeFiles/tester.dir/Messages/testMessage.cpp.o CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o CMakeFiles/tester.dir/__/src/Common/Fifo.cpp.o CMakeFiles/tester.dir/__/src/Common/Csu.cpp.o -o ../bin/tester -rdynamic -lboost_system -lpthread
CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o: In function `boost::detail::interruption_checker::interruption_checker(pthread_mutex_t*, pthread_cond_t*)':
/usr/local/include/boost/thread/pthread/thread_data.hpp:195: undefined reference to `boost::detail::get_current_thread_data()'
CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o: In function `boost::condition_variable::wait(boost::unique_lock<boost::mutex>&)':
/usr/local/include/boost/thread/pthread/condition_variable.hpp:81: undefined reference to `boost::this_thread::interruption_point()'
CMakeFiles/tester.dir/__/src/SharedData/SharedData.cpp.o: In function `boost::shared_mutex::lock_shared()':
/usr/local/include/boost/thread/pthread/shared_mutex.hpp:186: undefined reference to `boost::this_thread::disable_interruption::disable_interruption()'
/usr/local/include/boost/thread/pthread/shared_mutex.hpp:193: undefined reference to `boost::this_thread::disable_interruption::~disable_interruption()'
/usr/local/include/boost/thread/pthread/shared_mutex.hpp:193: undefined reference to `boost::this_thread::disable_interruption::~disable_interruption()'
Turns out my question is just like everyone else's.
#jww suggested I show the actual compile and link command invocation, not CMake's output, which I've added to my question. As you can see, the command is linking boost_system and pthread, but not boost_thread.
Digging into my project I realized that I had added boost_thread to my release build, but not into my unit test build, which is what I was trying to compile. Adding boost_thread to the unit test's CMakeLists.txt removed the error immediately.

cURL cross compile

How can I cross compile "cURL" for windows on linux(actually using kali)? Or is there a linux distro where the cross compile environment is already built or where the cross compile environment is simple to build?
Please Help!
I have Mingw working fine with header files already in its include directory. Now I compiled cURL and verified its existence in Mingw's include directory. But now when I include <curl/curl.h> in my code, this is the error I will get during compile time:
/tmp/ccsrpc1o.o:https.c:(.text+0x1c): undefined reference to `__imp__curl_global_init'
/tmp/ccsrpc1o.o:https.c:(.text+0x26): undefined reference to `__imp__curl_easy_init'
/tmp/ccsrpc1o.o:https.c:(.text+0x4a): undefined reference to `__imp__curl_easy_setopt'
/tmp/ccsrpc1o.o:https.c:(.text+0x5a): undefined reference to `__imp__curl_easy_perform'
/tmp/ccsrpc1o.o:https.c:(.text+0x73): undefined reference to `__imp__curl_easy_strerror'
/tmp/ccsrpc1o.o:https.c:(.text+0xb2): undefined reference to `__imp__curl_easy_cleanup'
/tmp/ccsrpc1o.o:https.c:(.text+0xbc): undefined reference to `__imp__curl_global_cleanup'
collect2: ld returned 1 exit status
First cross compile cURL with these commands:
$ ./configure --host=i586-mingw32msvc --enable-http --with-zlib --with-winssl
$ make
$ make install
And you can now compile your code(s):
$ i586-mingw32msvc-gcc -o https.exe https.c -lcurl
or
$ i586-mingw32msvc-gcc -o https.exe https.c /usr/i586-mingw32msvc/lib/libcurl.dll.a