Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot import nonprecompiled packages from embedding interface #14577

Closed
mlubin opened this issue Jan 6, 2016 · 14 comments · Fixed by #23525
Closed

cannot import nonprecompiled packages from embedding interface #14577

mlubin opened this issue Jan 6, 2016 · 14 comments · Fixed by #23525
Assignees
Labels
domain:embedding Embedding Julia using the C API

Comments

@mlubin
Copy link
Member

mlubin commented Jan 6, 2016

If I have a call, e.g.,

jl_eval_string("import MathProgBase");

and the MathProgBase package hasn't been precompiled, then I get an exception:

Base.UVError(prefix="could not spawn `/mnt/hdd/mlubin/julia-0.4/julia-bb73f3489d/lib/julia -Cnative -J/mnt/hdd/mlubin/julia-0.4/julia-bb73f3489d/lib/julia/sys.so --output-ji /home/mlubin/.julia/lib/v0.4/MathProgBase.ji --output-incremental=yes --startup-file=no --history-file=no --color=no --eval 'while !eof(STDIN)
    eval(Main, deserialize(STDIN))
end

The path /mnt/hdd/mlubin/julia-0.4/julia-bb73f3489d/lib/julia is a directory, not the julia binary.

@tkelman tkelman added domain:embedding Embedding Julia using the C API compiler:precompilation Precompilation of modules labels Jan 6, 2016
@vtjnash
Copy link
Sponsor Member

vtjnash commented Jan 6, 2016

you've probably set JULIA_HOME wrong. it should point to the julia executable.

@mlubin
Copy link
Member Author

mlubin commented Jan 6, 2016

I haven't set JULIA_HOME. I call

jl_init(JULIA_INIT_DIR);

with -DJULIA_INIT_DIR=\"/mnt/hdd/mlubin/julia-0.4/julia-bb73f3489d/lib\" where that define is produced by julia-config.jl --cflags.

@KristofferC
Copy link
Sponsor Member

Ref: https://groups.google.com/forum/?nomobile=true#!topic/julia-users/2sR6QdPLA80

I do the same as @mlubin. In CMakeLists.txt:

# Julia stuff
set(JULIA_PATH /home/kristoffer/julia0.4)
set(JULIA_LIB_DIR ${JULIA_PATH}/usr/lib)
add_definitions(-DJULIA_INIT_DIR="${JULIA_LIB_DIR}")

and in c++:

  jl_init(JULIA_INIT_DIR);

@mlubin
Copy link
Member Author

mlubin commented Jan 6, 2016

@KristofferC, is it working or broken for you with that configuration?

@KristofferC
Copy link
Sponsor Member

Broken as in the julia user post.

mlubin referenced this issue in bungun/cmpb Jan 6, 2016
@JeffBezanson JeffBezanson added the kind:bug Indicates an unexpected problem or unintended behavior label Feb 6, 2016
@mlubin
Copy link
Member Author

mlubin commented May 15, 2016

Bump, seems like a potential blocker for 0.5 to not be able to safely import packages from the embedding interface.
CC @SteveDiamond

@vtjnash vtjnash self-assigned this Jun 3, 2016
@ihnorton
Copy link
Member

Worked on this with @KristofferC and reproduced using ForwardDiff. The issue was that jl_init (or JULIA_HOME) needs to be the path containing the julia executable -- not the lib path, and not the path to the executable itself. Please re-open if needed.

@KristofferC
Copy link
Sponsor Member

Shouldn't the julia-config.jl script be modified to not point to the lib folder?

@Keno
Copy link
Member

Keno commented Jun 25, 2016

Yes

@Keno Keno reopened this Jun 25, 2016
@Keno
Copy link
Member

Keno commented Jun 25, 2016

Also, why is this needed at all? Is the path from libjulia to the system image not fixed?

@ihnorton
Copy link
Member

jl_init(NULL) works fine too. I'm not sure what the history is.

@vtjnash vtjnash removed kind:bug Indicates an unexpected problem or unintended behavior compiler:precompilation Precompilation of modules labels Aug 22, 2016
@ihnorton
Copy link
Member

As far as I can tell there is nothing to be done here. There have been a variety of changes to init.c, and the test script now works with default --cflags output, and still works with jl_init(NULL).

@ihnorton ihnorton reopened this Jun 2, 2017
@ihnorton
Copy link
Member

ihnorton commented Jun 2, 2017

Changing the embedding example code to:

int main()
{
    jl_init();

    jl_eval_string("import MathProgBase");
    if (jl_exception_occurred()) {
        jl_call2(jl_get_function(jl_base_module, "show"), jl_stderr_obj(), jl_exception_occurred());
        jl_printf(jl_stderr_stream(), "\n");
    }
}

gives

could not spawn `/Users/inorton/git/julia/usr/lib/julia -Cnative -J/Users/inorton/git/julia/usr/lib/julia/sys.dylib --compile=yes --depwarn=yes -O0 --output-ji /Users/inorton/.julia/lib/v0.7/MathProgBase.ji --output-incremental=yes --startup-file=no --history-file=no --color=no --eval 'while !eof(STDIN)
    eval(Main, deserialize(STDIN))
end
'`: permission denied (EACCES)

So I guess this is still/again an issue.

Ref: https://discourse.julialang.org/t/embedding-jullia-jl-init-julia-init-and-julia-home/4032

@Non-Contradiction
Copy link

I ran into the same issue in developing JuliaCall which embeds julia in R. I currently walk around the problem by doing things like system("julia -e 'using MathProgBase') in R first, which compiles the package, then I can just import the package in embedded julia.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:embedding Embedding Julia using the C API
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants