1

I install boost on ubuntu16.04 by apt-get install from the official source. then follow the installation guide of QuantLib

then I copy one of quantlib examples (Examples/EquityOption) to create my own project, I create one class in testoption.cpp and testoption.cpp now I have three files( testoption.hpp , testoption.cpp, and EquityOption.cpp)

in testoption.hpp

#ifndef TESTOPTION_HPP
#define TESTOPTION_HPP
#include <ql/quantlib.hpp>
using namespace QuantLib
class testOption{
//class declaration
};
#endif

in EquityOption.cpp

#include <ql/quantlib.hpp>
#include "testoption.hpp"
int main(int, char* [])
{
//some code here
}

in testoption.cpp

#include "testoption.hpp"
//definition of member function in testOption

whre i compile it and link to QuantLib, error emessage pop up:

CMakeFiles/EquityOption.dir/ATestClass.cpp.o: In function boost::function1<double, double>::get_vtable() const': /usr/local/include/boost/math/special_functions/detail/igamma_large.hpp:69: multiple definition ofQuantLib::MultiCurveSensitivities::performCalculations() const' CMakeFiles/EquityOption.dir/EquityOption.cpp.o:/usr/local/include/ql/experimental/termstructures/multicurvesensitivities.hpp:106: first defined here CMakeFiles/EquityOption.dir/ATestClass.cpp.o: In function QuantLib::MultiCurveSensitivities::allZeros() const': /usr/local/include/boost/math/special_functions/detail/igamma_large.hpp:112: multiple definition ofQuantLib::MultiCurveSensitivities::allZeros() const' CMakeFiles/EquityOption.dir/EquityOption.cpp.o:/usr/local/include/ql/experimental/termstructures/multicurvesensitivities.hpp:151: first defined here CMakeFiles/EquityOption.dir/ATestClass.cpp.o: In function QuantLib::MultiCurveSensitivities::sensitivities() const': /usr/local/include/boost/math/special_functions/detail/igamma_large.hpp:99: multiple definition ofQuantLib::MultiCurveSensitivities::sensitivities() const' CMakeFiles/EquityOption.dir/EquityOption.cpp.o:/usr/local/include/ql/experimental/termstructures/multicurvesensitivities.hpp:129: first defined here CMakeFiles/EquityOption.dir/ATestClass.cpp.o: In function QuantLib::MultiCurveSensitivities::inverseSensitivities() const': /usr/local/include/boost/math/special_functions/detail/igamma_large.hpp:100: multiple definition ofQuantLib::MultiCurveSensitivities::inverseSensitivities() const' CMakeFiles/EquityOption.dir/EquityOption.cpp.o:/usr/local/include/ql/experimental/termstructures/multicurvesensitivities.hpp:134: first defined here CMakeFiles/EquityOption.dir/ATestClass.cpp.o: In function QuantLib::MultiCurveSensitivities::allNodes() const': /usr/local/include/boost/math/special_functions/detail/igamma_large.hpp:101: multiple definition ofQuantLib::MultiCurveSensitivities::allNodes() const' CMakeFiles/EquityOption.dir/EquityOption.cpp.o:/usr/local/include/ql/experimental/termstructures/multicurvesensitivities.hpp:139: first defined here collect2: error: ld returned 1 exit status CMakeFiles/EquityOption.dir/build.make:123: recipe for target 'EquityOption' failed

I google around and find a similar question: Build error using head revision of rquantlib with head revision of QuantLib and boost 1.56 I try another solution of Why do I get a multiple definition error while linking?, but failed. I'm quite new to c++, should I also need to modify the source header file to make the the mothed inline and compile quantlib again(takes nearly twenty minutes with -j 4 option on my laptop)?

Community
  • 1
  • 1

1 Answers1

2

modify ql/experimental/terstrutures/multicurvesensitivities.hpp and make member functions of class Multicurvesensitivities to inline function and copy to default include path(in ubuntu 16.04 it's /usr/local/include/ql/experimental/terstructures) solved the problem.

  • 1
    Confirmed. For what is worth, the problem is fixed in the git repository. Another workaround (which might be a good idea regardless of the issue) would be to not include the global header `ql/quantlib.hpp` and instead include only the specific headers you need. This will have the further advantage of reducing compilation times. – Luigi Ballabio Dec 09 '16 at 18:36
  • 1
    Also, running `make` and `make install` after the modification might be safer than copying the header by hand. Only a few files will be affected and recompiled, so it won't take as long as the original compilation. – Luigi Ballabio Dec 09 '16 at 18:38