# Including Shared Object based on c Code

**URL:** <https://root-forum.cern.ch/t/including-shared-object-based-on-c-code/32937>\
**Category:** Newbie\
**Created:** [February 27, 2019, 9:25am UTC](https://root-forum.cern.ch/t/including-shared-object-based-on-c-code/32937 "2019-02-27T09:25:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Squirrel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@Squirrel](https://root-forum.cern.ch/u/Squirrel)\
**Post date:** [February 27, 2019, 9:25am UTC](https://root-forum.cern.ch/t/including-shared-object-based-on-c-code/32937/1 "2019-02-27T09:25:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [February 27, 2019, 1:40pm UTC](https://root-forum.cern.ch/t/including-shared-object-based-on-c-code/32937/2 "2019-02-27T13:40:18Z")

</div>

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")`

---

<div class="post-metadata">

**Author:** ![Squirrel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@Squirrel](https://root-forum.cern.ch/u/Squirrel)\
**Post date:** [February 27, 2019, 3:54pm UTC](https://root-forum.cern.ch/t/including-shared-object-based-on-c-code/32937/3 "2019-02-27T15:54:02Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![etejedor](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/e79b87/32.png) [@etejedor](https://root-forum.cern.ch/u/etejedor)\
**Post date:** [February 27, 2019, 4:13pm UTC](https://root-forum.cern.ch/t/including-shared-object-based-on-c-code/32937/4 "2019-02-27T16:13:19Z")

</div>

Then perhaps @Axel can shed some light on this?

---

<div class="post-metadata">

**Author:** ![Squirrel](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@Squirrel](https://root-forum.cern.ch/u/Squirrel)\
**Post date:** [March 5, 2019, 10:58am UTC](https://root-forum.cern.ch/t/including-shared-object-based-on-c-code/32937/5 "2019-03-05T10:58:18Z")

</div>

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

> <https://stackoverflow.com/questions/1041866/what-is-the-effect-of-extern-c-in-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).

---

<div class="post-metadata">

**Author:** ![Axel](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/axel/32/11084_2.png) [@Axel](https://root-forum.cern.ch/u/Axel)\
**Post date:** [March 18, 2019, 7:36am UTC](https://root-forum.cern.ch/t/including-shared-object-based-on-c-code/32937/6 "2019-03-18T07:36:19Z")

</div>

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

Thanks for reporting!
