Hello.
I want to compile dynamic library with ACLIC and link it it with another library compiled by gcc. And then use this library in CLING. How can i do that?
That’s what I have:
“ns_lib.hpp”:
#ifndef _NS_LIB_HPP_
# define _NS_LIB_HPP_
extern char const *gBuf;
extern int main_ns_lib();
#endif
“ns_lib.cpp”:
#ifndef _NS_LIB_CPP_
# define _NS_LIB_CPP_
# include "ns_lib.hpp"
# include <stdio.h>
# include "NS/FuncUtils.hxx"
# include "NS/CommonUtils.hxx"
char const *gBuf = "test buffer";
int main_ns_lib()
{
NS_abs_buf buf;
double a[] = {0, 1, 2};
NS_AbsBufInit(&buf);
printf("Hello world from main_ns_lib()!\n");
printf("Check FuncUtils: pol = %f\n", NS_PolF(a, 2, 1));
NS_AbsBufPushBack< double >(&buf, 2);
NS_AbsBufFini(&buf);
return (0);
}
#endif
where NS_abs_buf, NS_AbsBufInit, NS_AbsBufPushBack, NS_AbsBufFini
are from my CommonUtils
dynamic library, and NS_PolF
is from FuncUtils
dynamic library.
So, i try to compile the library with this script:
#include <string.h>
#include "root/TSystem.h"
void build_aclic(char const *aLib)
{
char strb[128];
gSystem->AddIncludePath("-I${TESTDIR}/src/include"); // includedir of "ns_lib.hpp"
sprintf(strb, "./src/test/root6/%s", aLib);
printf("compile 'ns_lib.cpp ...\n");
gSystem->AddLinkedLibs("-L/usr/local/lib/NSutils -lFuncUtils -lCommonUtils");
gSystem->CompileMacro(strb, "kfcv-", "ns_lib", "./build/aclic");
return;
}
The library “ns_lib.so” is created successfully.
Now I want to use this library in another script (“load_lib.cpp”):
#include "root/Rtypes.h"
#include "root/TROOT.h"
R__ADD_INCLUDE_PATH($PROJECTSDIR/test.world/src/include) // includedir of ns_lib.hpp and ns_lib2.hpp
#include "ns_lib.hpp"
#include "ns_lib2.hpp"
R__ADD_LIBRARY_PATH($PROJECTSDIR/test.world/build/aclic) // path of ns_lib.so
R__LOAD_LIBRARY(ns_lib.so)
int main_load_aclic_libs()
{
printf("libraries: %s\n", gSystem->GetLibraries());
main_ns_lib();
return (0);
}
But after loading this script in CLING (in ROOT session) with .L load_lib.cpp
I have the next:
cling::DynamicLibraryManager::loadLibrary(): libCommonUtils.so: cannot open shared object file: No such file or directory
Error in <AutoloadLibraryMU>: Failed to load library /home/nazar_s/devel/projects/test.world/build/aclic/ns_lib.socling JIT session error: Failed to materialize symbols: { (main, { _Z11main_ns_libv }) }
[runStaticInitializersOnce]: Failed to materialize symbols: { (main, { _Z20main_load_aclic_libsi, __stmts__0, _GLOBAL__sub_I_cling_module_10, __orc_init_func.cling-module-10, $.cling-module-10.__inits.0 }) }
So, what I’m doing wrong?
Best wishes,
Nazar