Including Shared Object based on c Code

Hello everyone,

hopefully my colleague and I didn’t miss any topic with the solution to our problem…

We are working on c-Code and managed to build (with gcc 5 and Eclipse Neon) a shared object. Now we are trying to get ROOT (6.16.00, built with our system) to interact with it. ROOT doesn’t seem to have a problem with including the file. But as soon as we try to call a function MemIsLittleEndian() we get the following error:

IncrementalExecutor::executeFunction: symbol ‘_Z19MemIsLittleEndianv’ unresolved while linking [cling interface function]!
You are probably missing the definition of MemIsLittleEndian()
Maybe you need to load the corresponding shared library?

We have been trying to work this out for a couple of days now, so hopefully somebody can help us.

Hello @Squirrel,

If I understand correctly, you are trying to load and use a shared library from ROOT?

You need to make sure that:

  • You include its header: gInterpreter->ProcessLine("#include \"my_cpp_library.h\"')
  • You load the library: gSystem->Load("./my_cpp_library.so")

Hey @etejedor,

thank you for answering!
I included all necessary Header Files (it’s a rather big c-Project) and the .so using .L
Nonetheless I tried what you suggested, without success though - I still get the same error.
(The auto-completion of ROOT shows me that it “sees” the function, so I conclude that at least the #include worked)

Then perhaps @Axel can shed some light on this?

We found the solution! The magic word is “extern C”:

With this we can call our functions (so happy!) - the only negative aspect about it though: The auto-completion doesn’t work anymore. (We solved this by simple declaring the prototype twice: First with ‘extern C’, the second time without - Not the other way around, because then root will detect an inconsistency with the language linkage).

Ha, interesting! That missing autocompletion is a bug. I can reproduce it, it’s now https://sft.its.cern.ch/jira/browse/ROOT-10042

Thanks for reporting!