Embedding: Ubuntu PPA library location

I am working on embedding the Julia interpreter as a library in a C++ application (in the context of testing julia bindings for a library).

At the moment, I doing experiments with the build from the ubuntu PPA https://launchpad.net/~staticfloat/+archive/ubuntu/juliareleases by @staticfloat.

While the libjulia.so library is found in /usr/lib/x86_64-linux-gnu/ as expected, a number of other shared libraries required by libjulia.so are installed into /usr/lib/x86_64-linux-gnu/julia.

ldd gives

linux-vdso.so.1 =>  (0x00007ffc7dbf5000)
libLLVM-3.7.1.so => /usr/lib/x86_64-linux-gnu/julia/libLLVM-3.7.1.so (0x00007f5641ca3000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f5641a7f000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f5641876000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f5641659000)
libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f56412d7000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f5640fcd000)
libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f5640db7000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f56409ee000)
/lib64/ld-linux-x86-64.so.2 (0x000055fca1548000)
libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f56407d3000)

So I need to add custom link directories with the cmake link_directories function.

I am wondering what is the proper way to deal with these extra shared libraries. The FindJulia.cmake that I am using is https://github.com/SylvainCorlay/xtensor-julia/blob/cpp-tests/deps/test/FindJulia.cmake

There is a script in contrib called julia-config.jl which should print out the necessary flags, but it does not appear to do so correctly in the PPA version of 0.5.

I would suggest doing any new embedding development work against the 0.6-beta nightly, because we recently made a number of improvements to the embedding API and Makefile. The following examples are from the latest generic nightly:

  • the ldlibs flag:
osboxes@osboxes:~/Downloads/julia-085876ee90$ bin/julia share/julia/julia-config.jl --ldlibs
  • the example Makefile now requires only the path to julia and the output binary directory (no dependency on the rest of the Julia build system):
osboxes@osboxes:~/Downloads/julia-085876ee90/share/doc/julia/examples/embedding$ make JULIA=~/Downloads/julia-085876ee90/bin/julia BIN=./

cc /home/osboxes/Downloads/julia-085876ee90/share/doc/julia/examples/embedding/embedding.c -o embedding -lm -std=gnu99 -DJULIA_ENABLE_THREADING=1 -fPIC -DJULIA_INIT_DIR=\"/home/osboxes/Downloads/julia-085876ee90/lib\" -I/home/osboxes/Downloads/julia-085876ee90/include/julia -L/home/osboxes/Downloads/julia-085876ee90/lib -Wl,--export-dynamic -Wl,-rpath,/home/osboxes/Downloads/julia-085876ee90/lib -Wl,-rpath,/home/osboxes/Downloads/julia-085876ee90/bin/../lib/julia -ljulia

Also, note that the only libraries you should need to worry about are libLLVM and libjulia. The rest of those are system libraries. We distribute a separate libLLVM in the PPA because either the distro version is too old, or we require patched LLVM (often both).

@ihnorton thanks for your response.

Since I am using cmake, I would rather not pass compilation flags directly. I found a way around the issue described earlier. Since julia does not provide a JuliaConfig.cmake and JuliaConfigVersion.cmake, I put together a FindJulia.cmake which interogates julia for its library and include directories, as well as the value that I should use for JULIA_HOME

The only remaining ad-hoc thing in my cmake is

find_library(LIBLLVM libLLVM libLLVM-3.7.1.so HINTS ${Julia_LIBRARY_DIR}/julia)

which directly requires knowing the full version string of libLLVM. If there was a cleaner way to retrieve this, it would be fantastic.

julia -e "println(Base.libllvm_version)"