How to put C-library in root environment?

I need step by step tutorial :frowning:

I have a sources of plain C-library and I need to use several C-functions in root scripts.

Evgueni

Assume you have a C lib with the functions aap(char*) and noot() in the source file bla.c do:

  • make bla.h:

#ifdef __cplusplus
extern “C” {
#endif

extern void aap(char *);
extern void noot();

#ifdef __cplusplus
}
#endif

  • make file blaLinkDef.h:

#ifdef CINT
#pragma link C++ function aap(char*);
#pragma link C++ function noot();
#endif

  • make a dictionary:

    rootcint -f blaDict.cxx -c bla.h blaLinkDef.h

    this generates blaDict.h and blaDict.cxx.

  • compile bla.c

    gcc -c -fPIC bla.c

  • compile the dictionary

    g++ -c -fPIC root-config --cflags blaDict.cxx

  • create the shared library

    g++ -shared -o bla.so bla.o blaDict.o

  • call aap() noot() from ROOT:

    $ root
    root [] gSystem->Load(“bla”)
    root [] aap(“pipo”)
    root [] noot()

That’s all.

Cheers, Fons.

Thank’s for working example :exclamation:

Evgueni

[quote=“rdm”]#ifdef CINT
#pragma link C++ function aap(char*);
#pragma link C++ function noot();
#endif
[/quote]
I found that sometimes declarations like

#pragma link C++ function kdb_lo_read (KDBconn *Conn,KDBlo *kl,char *Buffer,size_t len); causes troubles. rootcint doesn’t like names of variables. Is it Ok?

With declaration

#pragma link C++ function extern int kdb_lo_read (KDBconn *,KDBlo *,char *,size_t); everything is O’k.

Evgueni