我通过官方来源的apt-get install在ubuntu16.04上安装了boost。
然后按照QuantLib 的安装指南进行操作
然后我复制一个quantlib示例(Examples / EquityOption)以创建自己的项目,在testoption.cpp和testoption.cpp中创建一个类,现在我有三个文件(testoption.hpp,testoption.cpp和EquityOption.cpp)
在testoption.hpp中
#ifndef TESTOPTION_HPP
#define TESTOPTION_HPP
#include <ql/quantlib.hpp>
using namespace QuantLib
class testOption{
//class declaration
};
#endif
在EquityOption.cpp中
#include <ql/quantlib.hpp>
#include "testoption.hpp"
int main(int, char* [])
{
//some code here
}
在testoption.cpp中
#include "testoption.hpp"
//definition of member function in testOption
当我编译它并链接到QuantLib时,弹出错误消息:
CMakeFiles / EquityOption.dir / ATestClass.cpp.o:在函数
boost::function1<double, double>::get_vtable() const':/usr/local/include/boost/math/special_functions/detail/igamma_large.hpp:69: multiple definition of
QuantLib::MultiCurveSensitivities::performCalculations()const'中CMakeFiles / EquityOption.dir / EquityOption.cpp.o:/usr/local/include/ql/experimental/termstructures/multicurvesensitivities.hpp:106:首先在这里定义
CMakeFiles / EquityOption.dir / ATestClass.cpp.o:在函数
QuantLib::MultiCurveSensitivities::allZeros() const':/usr/local/include/boost/math/special_functions/detail/igamma_large.hpp:112: multiple definition of
QuantLib::MultiCurveSensitivities::allZeros()const'中CMakeFiles / EquityOption.dir / EquityOption.cpp.o:/usr/local/include/ql/experimental/termstructures/multicurvesensitiveivities.hpp:151:首先在这里定义
CMakeFiles / EquityOption.dir / ATestClass.cpp.o:在函数
QuantLib::MultiCurveSensitivities::sensitivities() const':/usr/local/include/boost/math/special_functions/detail/igamma_large.hpp:99: multiple definition of
QuantLib::MultiCurveSensitivities::sensitiveivities()const'中CMakeFiles / EquityOption.dir / EquityOption.cpp.o:/usr/local/include/ql/experimental/termstructures/multicurvesensitiveivities.hpp:129:首先在这里定义
CMakeFiles / EquityOption.dir / ATestClass.cpp.o:在函数
QuantLib::MultiCurveSensitivities::inverseSensitivities() const':/usr/local/include/boost/math/special_functions/detail/igamma_large.hpp:100: multiple definition of
QuantLib::MultiCurveSensitivities::inverseSensitivities()const'中CMakeFiles / EquityOption.dir / EquityOption.cpp.o:/usr/local/include/ql/experimental/termstructures/multicurvesensitiveivities.hpp:134:首先在这里定义
CMakeFiles / EquityOption.dir / ATestClass.cpp.o:在函数
QuantLib::MultiCurveSensitivities::allNodes() const':/usr/local/include/boost/math/special_functions/detail/igamma_large.hpp:101: multiple definition of
QuantLib::MultiCurveSensitivities::allNodes()const'中CMakeFiles / EquityOption.dir / EquityOption.cpp.o:/usr/local/include/ql/experimental/termstructures/multicurvesensitiveivities.hpp:139:首先在这里定义
collect2:错误:ld返回1退出状态
CMakeFiles / EquityOption.dir / build.make:123:目标“EquityOption”的配方失败
我四处搜寻,发现了一个类似的问题:
Build error using head revision of rquantlib with head revision of QuantLib and boost 1.56
我尝试了Why do I get a multiple definition error while linking?的另一种解决方案,但失败了。
我对C++还是很陌生,是否还需要修改源头文件以使其成为嵌入式方法并再次编译quantlib(在我的笔记本电脑上使用-j 4选项需要近二十分钟)?
最佳答案
修改ql / experimental / terstrutures / multicurvesensitiveivities.hpp并使Multicurvesensitiveivities类的成员函数内联函数并复制到默认包含路径(在ubuntu 16.04中,它是/ usr / local / include / ql / experimental / terstructures)解决了该问题。
关于c++ - "QuantLib::MulticurvesSensitivities:performCalculations() const'的quantlib多重定义,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41033287/