2

I just started this simple Quantlib date class in VC++ Express 2010:

#include <iostream>
#include <sstream>

#include "ql/time/date.hpp"

int main(int, char* [])
{
     QuantLib::Date d(1, QuantLib::January, 2010);
     std::cout<<da<<std::endl;
 }

When I compiled it, this is one of the errors:

1>ql_inout.obj : error LNK2019: unresolved external symbol "public: __thiscall QuantLib::Date::Date(int,enum QuantLib::Month,int)" (??0Date@QuantLib@@QAE@HW4Month@1@H@Z) referenced in function _main

It must be something I didn't setup correctly in 2010 project. I have compiled the library in Debug mode successfully.

1 Answers1

2

Not all headers include the pragma that tells the linker to add QuantLib. If you don't want to include the full headers—which is advisable, as they would increase a lot your compilation time—you can add

#include <ql/auto_link.hpp>

to the included headers.

(You could also add the library explicitly to the linker options, but that is a lot more work since you have to specify different library names depending on the configuration. auto_link.hpp does this for you.)

Luigi Ballabio
  • 4,128
  • 21
  • 29
  • Is there any side effect of using auto_link.hpp? I mean my original linking problem does get resolved. But then I can't compile anything because: 1>C:\Program Files\QuantLib-1.4\ql/experimental/callablebonds/discretizedcallablefixedratebond.hpp(34): error C2653: 'CallableBond' : is not a class or namespace name. I am not even using CallableBond class. This is on VC++ Express 2010 with Windows 8, if that matters. – user3078106 Apr 18 '14 at 01:05
  • It seems an unrelated problem. What are you doing exactly? – Luigi Ballabio Apr 18 '14 at 06:35
  • I think they are unrelated at all too. But somehow after I tried #include auto_link.hpp, everything fell apart. Couldn't get the simplest example working with the error. I had to reinstall QuantLib 1.4. Now it seems compile fine. – user3078106 Apr 18 '14 at 17:03