2014-05-20 28 views
1

代碼無法在Ubuntu上建立QuantLib

#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

您已經通過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的包被調用。

+0

我嘗試安裝libquantlib0,但它仍然給我同樣的問題。我嘗試按照[鏈接] http://quantess.net/2012/09/26/quantlib-get-it-working-on-ubuntu/中的步驟手動安裝軟件包,但仍面臨同樣的問題。有什麼想法嗎 ? – user721570

+0

你重新編譯了你的程序嗎?另外,是否有可能你還在拿起新的標題? 'quantlib-config'現在說什麼,你在用什麼? –