# Embedding Julia C question

**URL:** <https://discourse.julialang.org/t/embedding-julia-c-question/19428>\
**Category:** General Usage\
**Tags:** embedding\
**Created:** [January 9, 2019, 1:10pm UTC](https://discourse.julialang.org/t/embedding-julia-c-question/19428 "2019-01-09T13:10:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![timmm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/timmm/32/6760_2.png) [@timmm](https://discourse.julialang.org/u/timmm)\
**Post date:** [January 9, 2019, 1:10pm UTC](https://discourse.julialang.org/t/embedding-julia-c-question/19428/1 "2019-01-09T13:10:49Z")

</div>

Hi,  
I am struggling with the documentation on embedding Julia in C. Is there an obvious thing I am doing wrong?  
If I try the test example in: [Embedding Julia · The Julia Language](https://docs.julialang.org/en/v1/manual/embedding/index.html)  
i.e. calling:

```julia
JULIA_DIR=/home/julia-1.0.2
gcc -o test -fPIC -I$JULIA_DIR/include/julia -L$JULIA_DIR/lib test.c -ljulia $JULIA_DIR/lib/julia/libstdc++.so.6

```

I get the result in the terminal:

```julia
/tmp/cccutk9I.o: In function `main':
test.c:(.text+0x10): undefined reference to `jl_init'
collect2: error: ld returned 1 exit status

```

When I try the same on the server I get a different result in the terminal:

```julia
In file included from /home/julia-1.0.2/include/julia/julia.h:1619,
                 from test.c:1:
/home/julia-1.0.2/include/julia/locks.h: In function âjl_mutex_waitâ:
/home/julia-1.0.2/include/julia/locks.h:24: error: â__ATOMIC_ACQUIREâ undeclared (first use in this function)
/home/julia-1.0.2/include/julia/locks.h:24: error: (Each undeclared identifier is reported only once
/home/julia-1.0.2/include/julia/locks.h:24: error: for each function it appears in.)
/home/julia-1.0.2/include/julia/locks.h:37: error: â__ATOMIC_SEQ_CSTâ undeclared (first use in this function)
/home/julia-1.0.2/include/julia/locks.h: In function âjl_mutex_lockâ:
/home/julia-1.0.2/include/julia/locks.h:102: error: â__ATOMIC_SEQ_CSTâ undeclared (first use in this function)
/home/julia-1.0.2/include/julia/locks.h: In function âjl_mutex_unlock_nogcâ:
/home/julia-1.0.2/include/julia/locks.h:126: error: â__ATOMIC_SEQ_CSTâ undeclared (first use in this function)
/home/julia-1.0.2/include/julia/locks.h:126: error: â__ATOMIC_RELEASEâ undeclared (first use in this function)
/home/julia-1.0.2/include/julia/locks.h: In function âjl_mutex_unlockâ:
/home/julia-1.0.2/include/julia/locks.h:138: error: â__ATOMIC_SEQ_CSTâ undeclared (first use in this function)
In file included from test.c:1:
/home/julia-1.0.2/include/julia/julia.h: In function âjl_eh_restore_stateâ:
/home/julia-1.0.2/include/julia/julia.h:1645: error: â__ATOMIC_SEQ_CSTâ undeclared (first use in this function)

```

If I try the example in test/embedding ([julia/test/embedding at master · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/tree/master/test/embedding)). I get this error:

```julia
ib/julia/libstdc++.so.6
/usr/bin/ld: /tmp/ccJPgarI.o: undefined reference to symbol 'sqrt@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libm.so.6: error adding symbols: DSO missing
from command line
collect2: error: ld returned 1 exit status

```

and for the server the same error it have above.

Also is there a working example for Windows? On windows the file : julia-1.0.2/lib/julia/libstdc++.so.6 doesn’t exist. A working example would be great.

Cheers,  
Tim

---

<div class="post-metadata">

**Author:** ![alligatorme](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alligatorme/32/6962_2.png) [@alligatorme](https://discourse.julialang.org/u/alligatorme)\
**Post date:** [May 7, 2019, 2:28pm UTC](https://discourse.julialang.org/t/embedding-julia-c-question/19428/2 "2019-05-07T14:28:31Z")

</div>

#define JULIA\_ENABLE\_THREADING  
should appears before  
#include \<julia.h\>  
I change the order, the error gone!!Maybe it is not the answer for yours,but the same error pops up when the order is wrong. Thanks
