I'm trying to learn QuantLib, this is my first program with which i intend to check that my environment is ok and i'm able to link to quantlib:

#include <ql/time/all.hpp>

using namespace QuantLib;

int main ()
{
  Date d1(14, February, 2014);
  return 0;
}

I've got my quantlib libraries installed under /usr/local/lib, headers under /usr/local/include/ql. I try to compile this little program with:

$ LC_ALL=C g++ -Wall -lQuantLib -o sample1 quantlib-sample-1.cpp
/tmp/cc4Z2xsf.o: In function `main':
quantlib-sample-1.cpp:(.text+0x1f): undefined reference to `QuantLib::Date::Date(int, QuantLib::Month, int)'
collect2: error: ld returned 1 exit status

The thing gets worse if i include "ql/quantlib.hpp" (much more errors like the one above). I tried passing "-L/usr/local/lib" for if my ldconfig is not ok.

I'm a bit lost here... Any clue?

有帮助吗?

解决方案

The command used to compile is malformed. Library linking options need to go after outputs and inputs. This works:

$ LC_ALL=C g++ -Wall -o sample1 quantlib-sample-1.cpp -lQuantLib

With '-lQuantLib' at the end of the command.

It works both including 'ql/quantlib.hpp' or 'ql/time/all.hpp'.

其他提示

It works for me if I change the first line to the more general (and recommended) catch-all include:

edd@max:/tmp$ g++ -o qldate qldate.cpp -lQuantLib    ## no errors or warnings
edd@max:/tmp$ cat qldate.cpp 
#include <ql/quantlib.hpp>

using namespace QuantLib;

int main ()
{
  Date d1(14, February, 2014);
  return 0;
}
edd@max:/tmp$ 
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top