# JIT and libraries

**URL:** <https://root-forum.cern.ch/t/jit-and-libraries/20309>\
**Category:** Cling\
**Created:** [December 9, 2015, 10:28am UTC](https://root-forum.cern.ch/t/jit-and-libraries/20309 "2015-12-09T10:28:12Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![andrase](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/9fc348/32.png) [@andrase](https://root-forum.cern.ch/u/andrase)\
**Post date:** [December 9, 2015, 2:15pm UTC](https://root-forum.cern.ch/t/jit-and-libraries/20309/9 "2015-12-09T14:15:32Z")

</div>

It is still not clear to me whether you are talking about the statically linked lib or the shared object case here.

Yes, the symbol is present in (the function is called from) the offline compiled part, but as it is a statically linked lib, i do not see how that can help the JIT-ed part to find the symbol. To make the example more concrete:

sc.h`int inc();`

sc.cc[code]  
static int i = 0;

int inc()  
{  
return ++i;  
}[/code]

main.cc[code]#include “sc.h”  
#include “cling.h”  
#include \<stdio.h\>

int main()  
{  
printf(“static inc %d\n”, inc());  
char const src =  
“#include "sc.h"\n”  
“int dinc() { return inc(); }\n”;  
typedef int dinc(void);  
jit::DynamicCompiler\* dc = jit::new\_compiler(“libtest”); // pass -L. and -lsc to cling::Interpreter  
dinc\* dip = reinterpret\_cast\<dinc\*\>(jit::compile(\*dc, src, “dinc”));  
printf(“compiled\n”);  
if (dip) {  
printf(“dynamic inc %d\n”, (\*dip)());  
printf(“static inc %d\n”, inc());  
printf(“dynamic inc %d\n”, (\*dip)());  
}  
delete dc;  
}  
[/code]

```auto
$ gcc -c -o sc.o sc.cc
$ ar rcs libsc.a sc.o
$ g++ ... main.cc cling.cc ... -L. -lsc && ./a.out

static inc 1
compiled
IncrementalExecutor: calling unresolved symbol, see previous error message!
dynamic inc 47754048
static inc 2
IncrementalExecutor: calling unresolved symbol, see previous error message!
dynamic inc 47754048
```

> [@](#):
>
> The linker optimizes out the non used symbols. We request those explicitly in lib/Interpreter/RequiredSymbols.cpp

Previously i had a problem for which this might be the solution: [Missing std::string::operator=(std::string&&)](https://root-forum.cern.ch/t/missing-std-string-operator-std-string/20036/1) – do you mean that referencing e.g. the the std::string move constructor in symbol\_requester() would make it available for the JIT-ed code? I’d try it myself, but i can’t wrap my head around what’s going on in that function.

---

_[View the full topic](https://root-forum.cern.ch/t/jit-and-libraries/20309)._
