5

This might not even be a cling question, I'm a C++ newbie.

I am trying to play around with a library called QuantLib in the cling REPL.

I'm able to load the library in GCC by doing

#include "ql/quantlib.hpp"

and then compiling with -lQuantLib.

In cling I've been trying permutations of the 3 lines below:

.I "ql/quantlib.hpp"
#include "ql/quantlib.hpp"
.L QuantLib

If I run the #include first, I get a very long error, including stuff like

You are probably missing the definition of
QuantLib::AbcdAtmVolCurve::accept(QuantLib::AcyclicVisitor&) Maybe you
need to load the corresponding shared library?

But if I run

.I "ql/quantlib.hpp"
#include "ql/quantlib.hpp"

then all seems well.

.L Quantlib results in

input_line_4:1:10: fatal error: 'QuantLib' file not found
#include "QuantLib"

regardless of when it's run.

I tried the following after kfsone's comment

.L /usr/lib/libQuantLib.so
#include "ql/quantlib.hpp"

This gives a short error!

IncrementalExecutor::executeFunction: symbol '_ZN8QuantLib5ErrorC1ERKSslS2_S2_' unresolved while linking function '__cxx_global_var_init34'!
You are probably missing the definition of QuantLib::Error::Error(std::string const&, long, std::string const&, std::string const&)
Maybe you need to load the corresponding shared library?
piet.t
  • 11,718
  • 21
  • 43
  • 52

1 Answers1

4

Cling needs to know both the syntax of the structures/functions you want to use and have the binary code that executes.

For the syntax you have to add the include, for example like this:

#include "myfile.hpp"

For the binary code, you have to load the library like this:

#pragma cling load("myfile.so.9.220.0")
ben26941
  • 1,580
  • 14
  • 20