使用enable-sessions标志在Fedora 20上使用boost 1.5.4编译quantlib 1.9.2并运行其中一个示例,任何想法后获得以下错误?
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
注意:我尝试启用会话,因为在多线程客户端应用程序中使用quantlib时会出现段错误
答案 0 :(得分:1)
回答我自己的问题
1)将-lboost_system标志添加到编译器命令行后,pthread和boost_system错误消失了:
g++ BermudanSwaption.cpp -o BermudanSwaption -lQuantLib -lboost_system
这有助于:undefined reference to boost::system::system_category() when compiling
2)解决sessionId错误我在BermudanSwaption.cpp中添加了sessionId函数,如QL_ENABLE_SESSIONS所示:https://github.com/lballabio/QuantLib/blob/master/ql/userconfig.hpp
"您必须提供一个sessionId()并与库建立链接 命名空间QuantLib中的函数,返回不同的会话ID 为每个会议"
在我在BermudanSwaption.cpp中注释掉#if defined(QL_ENABLE_SESSIONS)
后,它编译时没有错误:
//#if defined(QL_ENABLE_SESSIONS)
namespace QuantLib {
Integer sessionId() { return 0; }
}
//#endif