代码
#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: In function `QuantLib::CPICoupon::indexFixing() const': test1.cpp:(.text._ZNK8QuantLib9CPICoupon11indexFixingEv[QuantLib::CPICoupon::indexFixing() const]+0x36): undefined reference to `QuantLib::CPICoupon::indexFixing(QuantLib::Date const&) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib22SwaptionVolatilityCubeE[vtable for QuantLib::SwaptionVolatilityCube]+0x100): undefined reference to `non-virtual thunk to QuantLib::SwaptionVolatilityDiscrete::update()' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib22SwaptionVolatilityCubeE0_NS_26SwaptionVolatilityDiscreteE[vtable for QuantLib::SwaptionVolatilityCube]+0xa8): undefined reference to `non-virtual thunk to QuantLib::SwaptionVolatilityDiscrete::update()' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib22CapFloorTermVolSurfaceE[vtable for QuantLib::CapFloorTermVolSurface]+0xc8): undefined reference to `non-virtual thunk to QuantLib::CapFloorTermVolSurface::update()' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib20CapFloorTermVolCurveE[vtable for QuantLib::CapFloorTermVolCurve]+0xc8): undefined reference to `non-virtual thunk to QuantLib::CapFloorTermVolCurve::update()' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib20SpreadedSmileSectionE[vtable for QuantLib::SpreadedSmileSection]+0x50): undefined reference to `QuantLib::SmileSection::optionPrice(double, QuantLib::Option::Type, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib20SpreadedSmileSectionE[vtable for QuantLib::SpreadedSmileSection]+0x58): undefined reference to `QuantLib::SmileSection::digitalOptionPrice(double, QuantLib::Option::Type, double, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib20SpreadedSmileSectionE[vtable for QuantLib::SpreadedSmileSection]+0x60): undefined reference to `QuantLib::SmileSection::vega(double, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib20SpreadedSmileSectionE[vtable for QuantLib::SpreadedSmileSection]+0x68): undefined reference to `QuantLib::SmileSection::density(double, double, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib20SpreadedSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::SpreadedSmileSection]+0x50): undefined reference to `QuantLib::SmileSection::optionPrice(double, QuantLib::Option::Type, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib20SpreadedSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::SpreadedSmileSection]+0x58): undefined reference to `QuantLib::SmileSection::digitalOptionPrice(double, QuantLib::Option::Type, double, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib20SpreadedSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::SpreadedSmileSection]+0x60): undefined reference to `QuantLib::SmileSection::vega(double, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib20SpreadedSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::SpreadedSmileSection]+0x68): undefined reference to `QuantLib::SmileSection::density(double, double, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib10FdmBatesOpE[vtable for QuantLib::FdmBatesOp]+0x60): undefined reference to `QuantLib::FdmBatesOp::toMatrixDecomp() const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib16FlatSmileSectionE[vtable for QuantLib::FlatSmileSection]+0x50): undefined reference to `QuantLib::SmileSection::optionPrice(double, QuantLib::Option::Type, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib16FlatSmileSectionE[vtable for QuantLib::FlatSmileSection]+0x58): undefined reference to `QuantLib::SmileSection::digitalOptionPrice(double, QuantLib::Option::Type, double, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib16FlatSmileSectionE[vtable for QuantLib::FlatSmileSection]+0x60): undefined reference to `QuantLib::SmileSection::vega(double, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib16FlatSmileSectionE[vtable for QuantLib::FlatSmileSection]+0x68): undefined reference to `QuantLib::SmileSection::density(double, double, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib16FlatSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::FlatSmileSection]+0x50): undefined reference to `QuantLib::SmileSection::optionPrice(double, QuantLib::Option::Type, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib16FlatSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::FlatSmileSection]+0x58): undefined reference to `QuantLib::SmileSection::digitalOptionPrice(double, QuantLib::Option::Type, double, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib16FlatSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::FlatSmileSection]+0x60): undefined reference to `QuantLib::SmileSection::vega(double, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTCN8QuantLib16FlatSmileSectionE0_NS_12SmileSectionE[vtable for QuantLib::FlatSmileSection]+0x68): undefined reference to `QuantLib::SmileSection::density(double, double, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib27CPICapFloorTermPriceSurfaceE[vtable for QuantLib::CPICapFloorTermPriceSurface]+0xb0): undefined reference to `QuantLib::CPICapFloorTermPriceSurface::price(QuantLib::Period const&, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib27CPICapFloorTermPriceSurfaceE[vtable for QuantLib::CPICapFloorTermPriceSurface]+0xb8): undefined reference to `QuantLib::CPICapFloorTermPriceSurface::capPrice(QuantLib::Period const&, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib27CPICapFloorTermPriceSurfaceE[vtable for QuantLib::CPICapFloorTermPriceSurface]+0xc0): undefined reference to `QuantLib::CPICapFloorTermPriceSurface::floorPrice(QuantLib::Period const&, double) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib27CPICapFloorTermPriceSurfaceE[vtable for QuantLib::CPICapFloorTermPriceSurface]+0x128): undefined reference to `QuantLib::CPICapFloorTermPriceSurface::cpiOptionDateFromTenor(QuantLib::Period const&) const' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib9CPICouponE[vtable for QuantLib::CPICoupon]+0x30): undefined reference to `QuantLib::CPICoupon::accept(QuantLib::AcyclicVisitor&)' /tmp/cc0GDoC4.o:(.data.rel.ro._ZTVN8QuantLib9CPICouponE[vtable for QuantLib::CPICoupon]+0x78): undefined reference to `QuantLib::CPICoupon::checkPricerImpl(boost::shared_ptr const&) const' collect2: ld returned 1 exit status
你能帮我吗?
答案 0 :(得分:1)
您已经通过apt-get
安装了QuantLib 1.1二进制文件,但是您是否包含了较新版本的标题(可能是您下载的标题?)
较新的头定义了更多的函数,这些函数在1.1二进制文件中缺失并导致链接器错误。
为避免错误,您需要使用同一版本的标头和二进制文件。 要使用较新的,请自行编译和安装QuantLib二进制文件;它应该像执行一样简单:
./configure
make
sudo make install
要使用1.1版本,您需要安装包含标题的dev
包。在我的系统上,它将通过执行
sudo apt-get install libquantlib0-dev
但是我再次提到libquantlib0
而不是libquantlib-1.1
,所以你最好运行apt-cache search quantlib
并找出dev包的名称。