Embedding Julia C question

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
i.e. calling:

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:

/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:

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). I get this error:

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

#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