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

ccall fails from embedding Julia into C #17451

Closed
akorotkov opened this issue Jul 16, 2016 · 7 comments
Closed

ccall fails from embedding Julia into C #17451

akorotkov opened this issue Jul 16, 2016 · 7 comments
Labels
docs This change adds or pertains to documentation embedding Embedding Julia using the C API

Comments

@akorotkov
Copy link

Hi!

I'm trying to run following example of embedding Julia into C.

#include <julia.h>

int my_func()
{
    return 1;
}

int main(int argc, char *argv[])
{
    /* required: setup the julia context */
    jl_init(JULIA_INIT_DIR);

    /* run julia commands */
    jl_eval_string(
        "try\n"
        "    print(ccall(:my_func, Cint, ()))\n"
        "catch err\n"
        "    print(\"$err\n\")\n"
        "end\n"
    );

    /* strongly recommended: notify julia that the
         program is about to terminate. this allows
         julia time to cleanup pending write requests
         and run all finalizers
    */
    jl_atexit_hook(0);
    return 0;
}

And I got following error.

ErrorException("ccall: could not find function my_func")

The OS is CentOS Linux 7.1, compiler is gcc 4.8.5.

julia version 0.4.6 is installed from nalimilan/julia repository.
I'm building example using following command.

/usr/share/julia/julia-config.jl --cflags --ldflags --ldlibs | xargs clang embed.c -o embed

The same example works fine for me on Mac OS X 10.10.5.
What am I doing wrong?

@tkelman tkelman added the embedding Embedding Julia using the C API label Jul 16, 2016
@yuyichao
Copy link
Contributor

-Wl,--export-dynamic

@yuyichao yuyichao added the docs This change adds or pertains to documentation label Jul 16, 2016
@akorotkov
Copy link
Author

It works! Many thanks!

@tkelman
Copy link
Contributor

tkelman commented Jul 16, 2016

Should that be added (sometimes?) to julia-config.jl ?

@yuyichao
Copy link
Contributor

The option only makes sense for executables and not for shared objects (not sure if any linker gives warning or error for that though) so it shouldn't be added to julia-config.jl unless we have different options for executables and libraries.

@yuyichao
Copy link
Contributor

This option is also not really necessary to make julia function correctly, only when a symbol in the main executable is looked up dynamically so it feels a little strange to require it. I do agree we should document this since many people might want to do this and hence the doc label.

@tkelman
Copy link
Contributor

tkelman commented Jul 16, 2016

this also looks like exactly the same question as https://groups.google.com/forum/#!topic/julia-users/rj8i4r6id9M

@yuyichao
Copy link
Contributor

Ha, I thought that was an issue which is why I couldn't find it just now .....

yuyichao added a commit that referenced this issue Jul 16, 2016
* Include threading flags. Fix #16868
* Add document about exporting symbols from main executable. Fix #17451
yuyichao added a commit that referenced this issue Jul 16, 2016
* Include threading flags. Fix #16868
* Add document about exporting symbols from main executable. Fix #17451
yuyichao added a commit that referenced this issue Jul 16, 2016
* Include threading flags. Fix #16868
* Add document about exporting symbols from main executable. Fix #17451
vtjnash pushed a commit that referenced this issue Jul 18, 2016
* Include threading flags. Fix #16868
* Add document about exporting symbols from main executable. Fix #17451
mfasi pushed a commit to mfasi/julia that referenced this issue Sep 5, 2016
* Include threading flags. Fix JuliaLang#16868
* Add document about exporting symbols from main executable. Fix JuliaLang#17451
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs This change adds or pertains to documentation embedding Embedding Julia using the C API
Projects
None yet
Development

No branches or pull requests

3 participants