我在编译我的项目时遇到了一个问题。当我设置这一行时:
boost::shared_ptr mySwap;
我没有问题,但是当我设置这个时:
boost::shared_ptr mySwap(new OvernightVsLiborBasisSwap(OvernightVsLiborBasisSwap::PayerOvernight, 1.0, scheduleOis, indexOis, dayCountOis, 1.0, scheduleLibor, indexLibor, dayCountLibor));
我有以下错误消息
excelFunctions.obj:错误 LNK2019:未解析的外部符号“公共:__thiscall ModLibNY::OvernightVsLiborBasisSwap::OvernightVsLiborBasisSwap(enum ModLibNY::OvernightVsLiborBasisSwap::Type,double,class QuantLib::Schedule const &,class boost::shared_ptr const &,class QuantLib::DayCounter const &,double,class QuantLib::Schedule const &,class boost::shared_ptr const &,class QuantLib::DayCounter const &,double,double,bool,bool,class boost::optional,class boost: :optional)" (??0OvernightVsLiborBasisSwap@ModLibNY@@QAE@W4Type@01@NABVSchedule@QuantLib@@ABV?$shared_ptr@VOvernightIndex@QuantLib@@@boost@@ABVDayCounter@4@N1ABV?$shared_ptr@VIborIndex@QuantLib@ @@6@3NN_N5V?$optional@W4BusinessDayConvention@QuantLib@@@6@6@Z) 在函数 "class xlw::NCMatrix __cdecl getOisLiborSwapCurve(class xlw::CellMatrix const &,class xlw::CellMatrix const &,class xlw::CellMatrix const &,class xlw::CellMatrix const &,double const &)" (?getOisLiborSwapCurve@@YA?AVNCMatrix@xlw@@ABVCellMatrix@2@000ABN @Z) 3>.\Debug\ExplainPnL.xll : 致命错误 LNK1120: 1 unresolved externals
对象 OvernightVsLiborBasisSwap 是我自己制作的静态库 ModLibNY 的一部分,其中包含。我的代码的第一行包含:
#include <ql/quantlib.hpp>
#include <ml/modlibny.hpp>
#include <ml/swaps/overnightvsliborbasisswap.hpp>
using namespace std;
using namespace xlw;
using namespace QuantLib;
using namespace ModLibNY;
非常奇怪的是,当我使用构造函数时出现错误。有关信息,它在 .hpp 文件中声明为
#ifndef overnight_vs_libor_basis_swap_hpp
#define overnight_vs_libor_basis_swap_hpp
#include <ql/quantlib.hpp>
using namespace std;
using namespace QuantLib;
namespace ModLibNY {
class InterestRateIndex;
class OvernightVsLiborBasisSwap : public Swap {
public:
enum Type { ReceiverOvernight = -1, PayerOvernight = 1 };
class arguments;
class results;
class engine;
OvernightVsLiborBasisSwap(
const OvernightVsLiborBasisSwap::Type type,
const Real nominal1,
const Schedule &schedule1,
const boost::shared_ptr<OvernightIndex> &index1,
const DayCounter &dayCount1,
const Real nominal2,
const Schedule &schedule2,
const boost::shared_ptr<IborIndex> &index2,
const DayCounter &dayCount2,
const Real spread1 = 0.0,
const Real spread2 = 0.0,
const bool intermediateCapitalExchange = false,
const bool finalCapitalExchange = false,
boost::optional<BusinessDayConvention> paymentConvention1 =
boost::none,
boost::optional<BusinessDayConvention> paymentConvention2 =
boost::none);
并在 .cpp 文件中定义:
#include "StdAfx.h"
#include "overnightvsliborbasisswap.hpp"
#include <ql/quantlib.hpp>
using namespace QuantLib;
命名空间 ModLibNY {
OvernightVsLiborBasisSwap::OvernightVsLiborBasisSwap(
const OvernightVsLiborBasisSwap::Type type,
const Real nominal1,
const Schedule &schedule1,
const boost::shared_ptr<OvernightIndex> &index1,
const DayCounter &dayCount1,
const Real nominal2,
const Schedule &schedule2,
const boost::shared_ptr<IborIndex> &index2,
const DayCounter &dayCount2,
const Real spread1,
const Real spread2,
const bool intermediateCapitalExchange,
const bool finalCapitalExchange,
boost::optional<BusinessDayConvention> paymentConvention1,
boost::optional<BusinessDayConvention> paymentConvention2)
: Swap(2),
type_(type),
nominal1_(std::vector<Real>(schedule1.size() - 1, nominal1)),
nominal2_(std::vector<Real>(schedule2.size() - 1, nominal2)),
schedule1_(schedule1),
schedule2_(schedule2),
index1_(index1),
index2_(index2),
dayCount1_(dayCount1),
dayCount2_(dayCount2),
intermediateCapitalExchange_(intermediateCapitalExchange),
finalCapitalExchange_(finalCapitalExchange)
{
init(paymentConvention1, paymentConvention2);
}
...如果有人知道问题的根源,请告诉我!
谢谢