码
#include <ql/quantlib.hpp>
#include <boost/timer.hpp>
int main ()
{
return 0;
}
库安装
sudo apt-get install libquantlib-1.1
QuantLib配置
$quantlib-config --libs
-L/usr/lib -lQuantLib
$ quantlib-config --cflags
-I/usr/include
$
编译和链接步骤:
$ g++ test1.cpp -L / usr / lib -lQuantLib -I / usr / include -fPIC -o test1
/tmp/cc0GDoC4.o:在函数QuantLib::CPICoupon::indexFixing()const中:
test1.cpp :(。text._ZNK8QuantLib9CPICoupon11indexFixingEv [QuantLib::CPICoupon::indexFixing()const] + 0x36): undefined reference `QuantLib::CPICoupon::indexFixing(QuantLib::Date const&)const'
/tmp/cc0GDoC4.o :(。data.rel.ro._ZTVN8QuantLib22SwaptionVolatilityCubeE [用于QuantLib::SwaptionVolatilityCube的vtable] + 0x100):未定义对QuantLib::SwaptionVolatilityDiscrete::update(')的非虚拟重击
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib22SwaptionVolatilityCubeE0_NS_26SwaptionVolatilityDiscreteE[vTable for QuantLib::SwaptionVolatilityCube] + 0xa8): undefined reference '非虚拟thunk:将Disvol:
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib22CapFloorTermVolSurfaceE[vTable for QuantLib::CapFloorTermVolSurface] + 0xc8):未定义对QuantLib::CapFloorTermVol(Surface:
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib20CapFloorTermVolCurveE[vTable for QuantLib::CapFloorTermVolCurve] + 0xc8):未定义对QuantLib::CapFloorTermVolCurve的非虚拟重击:
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib20SpreadedSmileSectionE[vTable for QuantLib::SpreadedSmileSection] + 0x50):未定义对`QuantLib::SmileSection::optionPrice(double,QuantLib::Option::Type, double)const'
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib20SpreadedSmileSectionE[vTable for QuantLib::SpreadedSmileSection] + 0x58):未定义对`QuantLib::SmileSection::digitalOptionPrice(double,QuantLib::Option::Type, double,double)const'
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib20SpreadedSmileSectionE[vTable for QuantLib::SpreadedSmileSection] + 0x60):对QuantLib::SmileSection::vega(double,double)const的 undefined reference
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib20SpreadedSmileSectionE[vTable for QuantLib::SpreadedSmileSection] + 0x68):未定义对`QuantLib::SmileSection::density(double,double,double)const'的引用
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib20SpreadedSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::SpreadedSmileSection] + 0x50):未定义对`QuantLib::SmileSection::optionPrice(double,QuantLibType: double)const'
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib20SpreadedSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::SpreadedSmileSection] + 0x58):对`QuantLib::SmileSection::digitalOptionType(double,QuantLib: double,double)const'
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib20SpreadedSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::SpreadedSmileSection] + 0x60):未定义对`QuantLib::SmileSection::vega(double,double)的引用
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib20SpreadedSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::SpreadedSmileSection] + 0x68):未定义对“QuantLib::SmileSection::density”的引用(常量, double , double , double , double
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib10FdmBatesOpE[vTable for QuantLib::FdmBatesOp] + 0x60):对QuantLib::FdmBatesOp::toMatrixDecomp()的 undefined reference
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib16FlatSmileSectionE[vTable for QuantLib::FlatSmileSection] + 0x50):未定义对`QuantLib::SmileSection::optionPrice(double,QuantLib::Option::Type, double)const'
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib16FlatSmileSectionE[vTable for QuantLib::FlatSmileSection] + 0x58):未定义对`QuantLib::SmileSection::digitalOptionPrice(double,QuantLib::Option::Type, double,double)const'
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib16FlatSmileSectionE[vTable for QuantLib::FlatSmileSection] + 0x60):未定义对`QuantLib::SmileSection::vega(double,double)const'的引用
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib16FlatSmileSectionE[vTable for QuantLib::FlatSmileSection] + 0x68):未定义对“QuantLib::SmileSection::density(double,double,double)const”的引用
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib16FlatSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::FlatSmileSection] + 0x50):未定义对`QuantLib::SmileSection::optionPrice(double,QuantType:Option, double)const'
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib16FlatSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::FlatSmileSection] + 0x58):未定义对`QuantLib::SmileSection::digitalOptionPrice(double,QuantLib: double,double)const'
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib16FlatSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::FlatSmileSection] + 0x60):未定义对`QuantLib::SmileSection::vega(double,double)const'的引用
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib16FlatSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::FlatSmileSection] + 0x68): undefined reference 'QuantLib::SmileSection::density(double,double,double)
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib27CPICapFloorTermPriceSurfaceE[vTable for QuantLib::CPICapFloorTermPriceSurface] + 0xb0):未定义对`QuantLib::CPICapFloorTermPriceSurface::price(QuantLib :)
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib27CPICapFloorTermPriceSurfaceE[vTable for QuantLib::CPICapFloorTermPriceSurface] + 0xb8):未定义对`QuantLib::CPICapFloorTermPriceSurface::capPrice()的引用,)
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib27CPICapFloorTermPriceSurfaceE[vTable for QuantLib::CPICapFloorTermPriceSurface] + 0xc0): undefined reference `QuantLib::CPICapFloorTermPriceSurface::bloorPrice()
/tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib27CPICapFloorTermPriceSurfaceE[vTable for QuantLib::CPICapFloorTermPriceSurface] + 0x128):未定义对QuantLib::CPICapFloorTermPriceSurface的引用:: cpiOptionDateFrom()
/tmp/cc0GDoC4.o :(。data.rel.ro._ZTVN8QuantLib9CPICouponE [适用于QuantLib::CPICoupon的vtable] + 0x30): undefined reference QuantLib::CPICoupon::accept(QuantLib::AcyclicVisitor&)
/tmp/cc0GDoC4.o :(。data.rel.ro._ZTVN8QuantLib9CPICouponE [适用于QuantLib::CPICoupon的vtable] + 0x78): undefined reference `QuantLib::CPICoupon::checkPricerImpl(boost::shared_ptr const&)const'
collect2:ld返回1退出状态
请你帮助我好吗 ?
最佳答案
您已经通过apt-get
安装了QuantLib 1.1二进制文件,但其中包括了较新版本(可能是您下载的版本)中的 header 。
较新的 header 定义了更多功能,而1.1二进制文件中缺少这些功能,并且会导致链接器错误。
为避免这些错误,您需要使用相同版本的 header 和二进制文件。
要使用较新的版本,请自己编译并安装QuantLib二进制文件。它应该像执行一样简单:
./configure
make
sudo make install
要改为使用1.1版本,您需要安装包含 header 的
dev
软件包。在我的系统上,可以通过执行sudo apt-get install libquantlib0-dev
但是话又说回来,我有
libquantlib0
而不是您提到的libquantlib-1.1
,因此您最好运行apt-cache search quantlib
并找出开发包的名称。
关于c++ - 无法在ubuntu上构建QuantLib,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23767355/