Loading a library with CINT

Hello,

I have a compiled library (.so file) but I dont have the source code, only the header file.
How can I load and use the functions inside this library with CINT?

Luciano

Hi,

Simply use ACLiC. For a library libTheirStuff.so with a header file theirStuff.h do

root [].include where_their_stuff_include_are/include root [] .L libTheirStuff.so root [] .L theirStuff.h+

Cheers,
Philippe.

When I do “.L ftd2xx.h+” I get the error:

Info in TUnixSystem::ACLiC: creating shared library /home/luciano/software/root/v5.16/macros/ftd2xx_h.so
Error: Symbol pthread_cond_teCondVar is not defined in current scope /home/luciano/software/root/v5.16/macros/ftd2xx.h:64:
Error: Symbol pthread_mutex_teMutex is not defined in current scope /home/luciano/software/root/v5.16/macros/ftd2xx.h:65:
Error: Symbol EVENT_HANDLE is not defined in current scope /home/luciano/software/root/v5.16/macros/ftd2xx.h:67:
Warning: Error occurred during reading source files
Warning: Error occurred during dictionary source generation
!!!Removing /home/luciano/software/root/v5.16/macros/file6sFCDY.cxx /home/luciano/software/root/v5.16/macros/file6sFCDY.h !!!
Error: rootcint: error loading headers…
Error in : Dictionary generation failed!
Info in : Invoking compiler to check macro’s validity
fileJ2UsDF.check.cxx:63: error: expected unqualified-id before ‘/’ token
fileJ2UsDF.check.cxx:67: error: expected constructor, destructor, or type conversion before ‘;’ token

I am sending the files.
Can you try to do this in your machine, please?

Luciano
macros.tar.gz (118 KB)

Hi,

You need to use the following wrapper around the header file to work around a few defects in CINT:

[code]// File named ftd2xx.cxx
#ifdef CINT
class pthread_cond_t;
class pthread_mutex_t;
#endif

#include “ftd2xx.h”

#ifdef MAKECINT
#pragma link off class _FTCOMSTAT-;
#pragma link off class _FTDCB-;
#endif[/code]

and use as before root [2] .L libftd2xx.so root [3] .L ftd2xx.cxx+

Cheers,
Philippe

Hi Philippe,

It really works!!!

Thank you very much.
Luciano

Hello Philippe,

I can load the library without any error on root now.
I also execute the functions of the library and root does not return erros.
But I could not see any modification on the hardware I am trying to access with this library.
It seems root is not really accessing the library (.so file).
Is it possible?

Luciano

[quote]But I could not see any modification on the hardware I am trying to access with this library. It seems root is not really accessing the library (.so file). [/quote]It is possible but unlikely. More likely is that the value being passed are incorrect (or incorrectly translated).
Are you to read the code in a debugger and put a break point in one (or more) of the library function?

Cheers,
Philippe.

I am thinking to create another library with more simple functions witch encapsulates all this hardware calls. So root does not need to interpret all these strange variables and structures.
What do you think?

This will probably be much simplier indeed :slight_smile: and should also be easy.
You can write a small file which include (but possibly hides it from cint) your other header file and load via ACLiC.

Cheers,
Philippe.

Ok,

so, for instance, the function FT_CreateDeviceInfoList(&iNumDevs), should return the amount of devices connected to the USB ports.

How can I compile a simple C function called
int GetNDevices()
wich encapsulate this function and load this in root?

Hi,

forget my last email.
I just realized how easy it is.

I did this already.

cheers,
Luciano

Hi, Phillipe,
I have a similar problem. Your tricks in this post really help me reduce a lot of error message. However, I still got some error message which I don’t know how to deal with them. Thank for your helps.

The errors are as follows:

Info in TUnixSystem::ACLiC: creating shared library /home/gma/rootmacros/./rootOTClient_cpp.so
In file included from /home/gma/rootmacros/include/Threads.h:11,
from /home/gma/rootmacros/include/OTSocket.h:12,
from /home/gma/rootmacros/include/OTClient.h:12,
from /home/gma/rootmacros/./rootOTClient.cpp:17,
from /tmp/fileekcJli_rootcint.h:3,
from /tmp/awRTJ0_cint.cxx:1:
/home/gma/rootmacros/include/OTDef.h:36:12: error: no macro name given in #define directive
Error: external preprocessing failed. :0:
!!!Removing /home/gma/rootmacros/./file5TaW63.cxx /home/gma/rootmacros/./file5TaW63.h !!!
Error: rootcint: error loading headers…
Error in : Dictionary generation failed!
Info in : Invoking compiler to check macro’s validity
In file included from /home/gma/rootmacros/include/Threads.h:11,
from /home/gma/rootmacros/include/OTSocket.h:12,
from /home/gma/rootmacros/include/OTClient.h:12,
from /home/gma/rootmacros/./rootOTClient.cpp:17:
/home/gma/rootmacros/include/OTDef.h:36:12: error: no macro name given in #define directive
/home/gma/rootmacros/./rootOTClient.cpp: In member function ‘virtual void MyClient::onLogin()’:
/home/gma/rootmacros/./rootOTClient.cpp:61: warning: taking address of temporary

Attached please find the related files. My class is in rootOTClient.cpp. The header files and lib are in the zip file.

gma
headers.zip (308 KB)
rootOTClient.cpp (11.1 KB)

Cheers,
Philippe