Closed creme332 closed 1 year ago
you need to tell cling where to get the symbols you defined in SquareMatrix.cpp, either: 1: compile SquareMatrix.cpp into a .so and load it; put main into separate file. 2: Put code in SquareMatrix.cpp in prior cells (copy/paste), before calling A.solve_approx. There are some issues/workarounds for multiple functions in one cell; just split them up for now.
This all assumes that SquareMatrix.cpp doesn't rely on other third party routines. I just think of it where each cell that executes a function (vs defined) gets wrapped, compiled, linked, executed, and output streamed so you can view result. Basically the same as your normal C++ environ.
Thank you for your help. I ended up using your first recommendation because my SquareMatrix.cpp
file is too large to be broken down into multiple functions to put in separate cells.
SquareMatrix.cpp
has no third-party dependencies. I executed the following commands to create a shared library in the same directory as my notebook:
g++ -c -fPIC src/SquareMatrix.cpp -std=c++17
g++ SquareMatrix.o -shared -o libProject.so
My jupyter notebook then becomes:
#pragma cling load("libProject")
#include "src/SquareMatrix.h"
SquareMatrix A({{10, 1, 2, 3, 30},
{1, 15, 2, -5, 17},
{0, 1, 20, 3, 74},
{3, -10, -1, 25, 80}},
true);
A.solve_approx(1, {0, 0, 0, 0}, 3);
Then everything executes fine.
My file structure looks like this:
liGebra
folder is/home/mcl/githubrepos/liGebra
.SquareMatrix.h
contains a class interface of the classSquareMatrix
. (only declarations)SquareMatrix.cpp
uses#include "SquareMatrix.h"
and contains the actual code.I want to use the
SquareMatrix.h
file inside my notebookex.ipynb
. I tried:The first two cells execute without errors but the third one fails due to some linking error:
What I tried
#include "/home/mcl/githubrepos/liGebra/src/SquareMatrix.h"
#pragma cling add_include_path("./src/")
#include "SquareMatrix.h"
#pragma cling add_include_path("/home/mcl/githubrepos/liGebra/src/")
and#pragma cling add_library_path("/home/mcl/githubrepos/liGebra/src/")
#include "SquareMatrix.h"
Version
Any help is appreciated. Thank you.