简体   繁体   中英

How do you load a library with cling?

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?

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM