gpt4 book ai didi

c++ - "QuantLib::MulticurvesSensitivities:performCalculations() const' 的 quantlib 多重定义

转载 作者:行者123 更新时间:2023-11-30 03:35:44 25 4
gpt4 key购买 nike

我在 ubuntu16.04 上通过 apt-get install 从官方源安装了 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/multicurvesensitivities.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::sensitivities() const'CMakeFiles/EquityOption.dir/EquityOption.cpp.o:/usr/local/include/ql/experimental/termstructures/multicurvesensitivities.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/multicurvesensitivities.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/multicurvesensitivities.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++ 的新手,我是否还需要修改源头文件以使 mothed 内联并再次编译 quantlib(在我的笔记本电脑上使用 -j 4 选项需要将近 20 分钟)?

最佳答案

修改 ql/experimental/terstrutures/multicurvesensitivities.hpp 并使 Multicurvesensitivities 类的成员函数内联函数并复制到默认包含路径(在 ubuntu 16.04 中是/usr/local/include/ql/experimental/terstructures)解决了问题.

关于c++ - "QuantLib::MulticurvesSensitivities:performCalculations() const' 的 quantlib 多重定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41033287/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com