Skip to content

Commit

Permalink
Workaround for JuliaInterop#99 (could not load library on multiarch i…
Browse files Browse the repository at this point in the history
…nstalls)

Julia's embedding fails in jl_init if Julia is built and installed with
MULTIARCH_INSTALL=1, which it is in Debian and Ubuntu. It fails with:

    > julia_setup()
    Julia version 1.5.2 at location /usr/bin will be used.
    ERROR: could not load library "/usr/lib/x86_64-linux-gnu/../bin/../lib/x86_64-linux-gnu/julia/sys.so"
    /usr/lib/x86_64-linux-gnu/../bin/../lib/x86_64-linux-gnu/julia/sys.so: cannot open shared object file: No such file or directory

The problem is described at JuliaLang/julia#32614 (comment).

As a workaround, let's allow overriding the bindir by setting
JULIA_BINDIR environment variable (`/usr/bin` to fix this on Debian).

Fixes: JuliaInterop#99
  • Loading branch information
liskin committed Nov 6, 2020
1 parent 6190314 commit f87b28a
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 1 deletion.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# 0.17.1.9000

* Fix bug for Julia plot in RMarkdown document caused by change of knitr #1717.
* Workaround for #99: `ERROR: could not load library` on Debian/Ubuntu and
other systems which build Julia with `MULTIARCH_INSTALL=1` (#143 by @liskin).

# JuliaCall 0.17.1

Expand Down
7 changes: 7 additions & 0 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,13 @@ The issue is usually caused by updates in R, and it can be typically solved by s
JuliaCall::julia_setup(rebuild = TRUE)
```

### `ERROR: could not load library "/usr/lib/x86_64-linux-gnu/../bin/../lib/x86_64-linux-gnu/julia/sys.so"`

This error happens when Julia is built/installed with `MULTIARCH_INSTALL=1`, as
it is on e.g. Debian. It is caused by [the bindir-locating code in jl\_init not
being multiarch-aware](https://github.com/JuliaLang/julia/issues/32614#issuecomment-656787386).
To work around it, try setting `JULIA_BINDIR=/usr/bin` in your environment.

### How to Get Help

- One way to get help for Julia functions is just using `julia$help` as the following example:
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,15 @@ follows.
JuliaCall::julia_setup(rebuild = TRUE)
```

### `ERROR: could not load library "/usr/lib/x86_64-linux-gnu/../bin/../lib/x86_64-linux-gnu/julia/sys.so"`

This error happens when Julia is built/installed with
`MULTIARCH_INSTALL=1`, as it is on e.g. Debian. It is caused by [the
bindir-locating code in jl\_init not being
multiarch-aware](https://github.com/JuliaLang/julia/issues/32614#issuecomment-656787386).
To work around it, try setting `JULIA_BINDIR=/usr/bin` in your
environment.

### How to Get Help

- One way to get help for Julia functions is just using `julia$help`
Expand Down
7 changes: 6 additions & 1 deletion src/JuliaCall.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <stdlib.h>
#include <Rcpp.h>
#include "libjulia.h"

Expand All @@ -17,7 +18,11 @@ bool juliacall_initialize(const std::string& libpath) {
stop(get_last_loaded_symbol() + " - " + get_last_dl_error_message());
}

jl_init();
const char *julia_bindir = getenv("JULIA_BINDIR");
if (julia_bindir)
jl_init_with_image(julia_bindir, NULL);
else
jl_init();

if (!load_libjulia_modules()) {
stop(get_last_dl_error_message());
Expand Down
2 changes: 2 additions & 0 deletions src/libjulia.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ bool load_libjulia_symbols() {
// load jl_init
if (!(load_symbol(libjulia_t, "jl_init", (void**) &jl_init) || load_symbol(libjulia_t, "jl_init__threading", (void**) &jl_init)))
return false;
if (!(load_symbol(libjulia_t, "jl_init_with_image", (void**) &jl_init_with_image) || load_symbol(libjulia_t, "jl_init_with_image__threading", (void**) &jl_init_with_image)))
return false;
LOAD_JULIA_SYMBOL(jl_atexit_hook);
LOAD_JULIA_SYMBOL(jl_eval_string);

Expand Down
2 changes: 2 additions & 0 deletions src/libjulia.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ STATIC_INLINE jl_function_t *jl_get_function(jl_module_t *m, const char *name)
// initialization functions
JL_EXTERN int (*jl_is_initialized)(void);
JL_EXTERN void (*jl_init)(void);
JL_EXTERN void (*jl_init_with_image)(const char *julia_bindir,
const char *image_relative_path);
JL_EXTERN void (*jl_atexit_hook)(int status);

// front end interface
Expand Down

0 comments on commit f87b28a

Please sign in to comment.