what path to set in jl_init

441 views
Skip to first unread message

eric l

unread,
Jan 31, 2015, 6:37:15 PM1/31/15
to julia...@googlegroups.com

I am trying to compile and run embedding.c on a 10.9.5 OS X Mac.
Compile without a glitch 
but when I run the executable I get:

> ./embedd 

dyld: Library not loaded: @rpath/libjulia.dylib

  Referenced from: /Users/doe/./embedd

  Reason: image not found

Trace/BPT trap: 5

I have try with jl_init set to: NULL,  $JULIA_DIR/   $JULIA_DIR/bin  $JULIA_DIR/lib/julia

 (with $JULIA_DIR fully extended ;) 

and get the same error over and over...

So what path should I write in jl_init () or should I do something different? 

Thxs. 

PS: 

Julia Version 0.3.5

Commit a05f87b* (2015-01-08 22:33 UTC)

Platform Info:

  System: Darwin (x86_64-apple-darwin13.4.0)

  CPU: Intel(R) Core(TM) i7-4650U CPU @ 1.70GHz

  WORD_SIZE: 64

  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)

  LAPACK: libopenblas

  LIBM: libopenlibm

  LLVM: libLLVM-3.3


Jameson Nash

unread,
Jan 31, 2015, 7:18:59 PM1/31/15
to julia...@googlegroups.com
 you're executable seems to be compiled wrong and cannot be executed (missing the @rpath attribute). try giving the -Wl,-rpath,"$JULIA_DIR/lib" option in your linker command where you passed `-ljulia`

eric l

unread,
Jan 31, 2015, 8:02:08 PM1/31/15
to julia...@googlegroups.com
Thx Jameson,

By the way on OSX gcc default to this now:

Apple LLVM version 6.0 (clang-600.0.51) (based on LLVM 3.5svn)

Target: x86_64-apple-darwin13.4.0

So I was able to make some progress: 
first I got:

./embedd 

System image file "/Applications/Julia-0.3.5.app/Contents/Resources/julia/../lib/julia/sys.ji" not found

Which make sense as  the path should be julia/lib/julia/sys.ji
So I simply created a dir  lib/julia/ under Resources/
Then copied all the files in lib/julia into the new dir. 

I ran ./embedd again and got a long list of grievances and the expected output of embedding.c! 
All the unfounded libxxxx are in the same directories as libjulia.dylib. 
Clearly something is not quite right with the compiler settings I am using... 


>.embedd

Warning: error initializing module LinAlg:

ErrorException("error compiling __init__: error compiling check_blas: error compiling openblas_get_config: could not load module libopenblas: dlopen(libopenblas.dylib, 1): image not found")

Entropy pool not available to seed RNG; using ad-hoc entropy sources.

Warning: error initializing module Random:

ErrorException("could not load module libdSFMT: dlopen(libdSFMT.dylib, 1): image not found")

Warning: error initializing module GMP:

ErrorException("error compiling __init__: could not load module libgmp: dlopen(libgmp.dylib, 1): image not found")

Warning: error initializing module PCRE:

ErrorException("ccall: could not find function pcre_jit_stack_alloc in library libpcre")

sqrt(2.0) in C: 1.414214e+00

sqrt(2.0) in C: 1.414214e+00

x = [9.000000e+00 8.000000e+00 7.000000e+00 6.000000e+00 5.000000e+00 4.000000e+00 3.000000e+00 2.000000e+00 1.000000e+00 0.000000e+00 ]

my_func(5.0) = 10.000000

UndefVarError(:this_function_does_not_exist)

Jameson Nash

unread,
Jan 31, 2015, 9:53:42 PM1/31/15
to julia...@googlegroups.com

here’s what I get for debug info on embedding on 0.4-dev. since you are still getting errors, you might want to check what you are getting, and whether you’ve set JULIA_HOME correctly (it must point to the folder containing the julia binary).

julia/usr/bin$ otool -l embedding  | grep -C4 RPATH
   time stamp 2 Wed Dec 31 19:00:02 1969
      current version 120.0.0
compatibility version 1.0.0
Load command 18
          cmd LC_RPATH
      cmdsize 48
         path @executable_path/../lib/julia (offset 12)
Load command 19
--
      cmdsize 48
         path @executable_path/../lib/julia (offset 12)
Load command 19
          cmd LC_RPATH
      cmdsize 40
         path @executable_path/../lib (offset 12)
Load command 20
      cmd LC_FUNCTION_STARTS
julia/usr/bin$ otool -L embedding
embedding:
@rpath/libjulia.dylib (compatibility version 0.0.0, current version 0.0.0)
/usr/lib/libffi.dylib (compatibility version 1.0.0, current version 1.0.0)
/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1213.0.0)
/System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1151.16.0)
/System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 62.0.0)
/usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)

Jeff Waller

unread,
Jan 31, 2015, 11:10:28 PM1/31/15
to julia...@googlegroups.com
Instead of jl_init, I use the following 


jl_init_with_image((char*)install_directory.c_str(),(char*)"sys.ji");


where install_directory is the directory of libjulia (e.g. /usr/local/julia/lib/julia), but whatever corresponds to how you link using -Wl,rpath

eric l

unread,
Feb 1, 2015, 1:18:02 AM2/1/15
to julia...@googlegroups.com

Gentlemen,

Thank you very much, it now works. 

gcc -o embedd -I$JULIA_DIR/include/julia -L$JULIA_DIR/lib/julia -Wl,-rpath,"$JULIA_DIR/lib/julia"  -ljulia embedding.c 
    
in the C code replace jl_init (NULL) with 
  jl_init("JULIA_DIR/bin");  //Where JULIA_DIR is the path to a folder with bin and lib/julia subfolder. 

Jeff I have yet to try your approach but I will keep it mind.

Thanks again,

-Eric 
 

eric l

unread,
Feb 2, 2015, 3:17:06 PM2/2/15
to julia...@googlegroups.com
Me again...

I know try the same thing on my linux box.

gcc -o embedd -I/usr/include/julia -L/usr/lib/x86_64-linux-gnu/julia -ljulia embedding.c

And this time it doesn't even link...
All I get is the list of the jl_XXX used in embedding.c as undefined.

/tmp/cceyXOMb.o: In function `jl_get_function':
embedding.c:(.text+0x18): undefined reference to `jl_symbol'
embedding.c:(.text+0x2a): undefined reference to `jl_get_global'
/tmp/cceyXOMb.o: In function `my_c_sqrt':
embedding.c:(.text+0x4b): undefined reference to `sqrt'
/tmp/cceyXOMb.o: In function `main':
embedding.c:(.text+0x75): undefined reference to `jl_init'
embedding.c:(.text+0x7f): undefined reference to `jl_eval_string'
embedding.c:(.text+0x89): undefined reference to `jl_eval_string'
embedding.c:(.text+0xa1): undefined reference to `jl_float64_type'
embedding.c:(.text+0xb5): undefined reference to `jl_unbox_float64'
embedding.c:(.text+0xf7): undefined reference to `jl_base_module'
embedding.c:(.text+0x126): undefined reference to `jl_box_float64'
embedding.c:(.text+0x13d): undefined reference to `jl_call1'
...

Any idea on what I could be doing wrong this time?

Thxs,

-Eric

PS:
>  gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)

Jameson Nash

unread,
Feb 2, 2015, 3:33:12 PM2/2/15
to julia...@googlegroups.com
does it work if you move `-ljulia` to the end of the list? some versions of ld care about the order, and will only resolve dependencies from left to right

eric l

unread,
Feb 2, 2015, 4:44:49 PM2/2/15
to julia...@googlegroups.com
Yes it did!  
And adding  -lm in front -ljulia too. Interestingly enough on OSX with clang the linking to the math library is not needed.

And this time I used Jeff advice and put:

 jl_init_with_image("/usr/bin","../lib/x86_64-linux-gnu/julia/sys.ji");
instead of:  jl_init ("/usr/bin");

and compiled it with:

gcc -o embedd -I/usr/include/julia -L/usr/lib/x86_64-linux-gnu/julia  -Wl,-R/usr/lib/x86_64-linux-gnu/julia  embedding.c -lm -ljulia

Thanks Again!

-Eric.




 


Reply all
Reply to author
Forward
0 new messages