Skip to content

using shared libraries from other languages #53

@visr

Description

@visr

I'm interested in using this package for creating shared libraries that can be used from Fortran (or any other language that supports calling C-exported shared libraries).

Currently the shared libraries created here do contain the @ccallable functions given in the julia script. But if I'm correct these cannot be used directly because you need to call jl_init first, and anything else mentioned in the embedding docs. This is done in program.c, which is compiled to executable.

If I want to be able to call simple julia functions like Base.@ccallable f(x::Float64)::Float64 = 2.0 * x from a shared library, how would I go about that? Modify the program.c to compile as shared library and provide the initialization functions from libjulia there as well? If anyone could provide a minimal example that would be great.

I tried things like:

extern double f(double a);

#ifdef _OS_WINDOWS_
__declspec(dllexport) __cdecl
#endif
void my_jl_init(void)
{
    jl_init();
}

#ifdef _OS_WINDOWS_
__declspec(dllexport) __cdecl
#endif
double my_f(double a)
{
    return f(a);
}

But while my_jl_init seemed to work, if I do my_f after, it segfaults. Is this more or less the right approach however?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions