I want to embed a Julia module inside a C program. The documentation is not very c

I want to embed a Julia module inside a C program. The documentation is not very clear. Does someone know how to import a module? The example uses jl_function_t *func = jl_get_function(jl_base_module, "sqrt"); and I would like to do something like
jl_function_t *myfunc = jl_get_function(jl_mymodule_module, "myfunc");

Note that the original poster on Slack cannot see your response here on Discourse. Consider transcribing the appropriate answer back to Slack, or pinging the poster here on Discourse so they can follow this thread.
(Original message :slack:) (More Info)

I got answers from @mbauman and Xirui Zhao. Got these good references:

small breadcrumb: How to use Julia special functions inside c++ - Stack Overflow

Perhaps you need to call jl_load julia/toplevel.c at 985158ff5b138954c87db273ebfed2ca4321a67c · JuliaLang/julia · GitHub, also see Eval of Julia code · The Julia Language

Although my recommendation is to write your C program as a library and call it from Julia. You can pass Julia function pointers to C functions. Calling C and Fortran Code · The Julia Language.

I modified the example from the post from SGJ that @mbauman referred me to. I want to modify it in order to send back and forth arrays with zero copy. However, I don’t know what is missing. I’m sure that it is something silly.

#include <julia.h>
JULIA_DEFINE_FAST_TLS() // only define this once, in an executable (not in a shared library) if you want fast code.

typedef jl_array_t* (*erf_ptr)(jl_array_t * z);
// erf_ptr erf = NULL;

#include <iostream>
int main(int argc, char *argv[])
    jl_value_t* array_type = jl_apply_array_type((jl_value_t*)jl_float64_type, 1);
    double v[] = { .1, .2, .3, .4 };

    // Expected output
    // julia> [.1, .2, .3, .4] .|> SpecialFunctions.erf
    // 4-element Vector{Float64}:
    // 0.1124629160182849
    // 0.22270258921047847
    // 0.3286267594591274
    // 0.42839235504666845

    jl_array_t *x = jl_ptr_to_array_1d(array_type, v, 4, 0);
    // get a C function pointer to the Julia erf function compiled for
    jl_eval_string("import SpecialFunctions");
    jl_value_t *ret = jl_eval_string("@cfunction(x->SpecialFunctions.erf.(x), Vector{Float64},(Vector{Float64},))");
    erf_ptr erf = (erf_ptr) jl_unbox_voidpointer(ret);

    jl_array_t*  out = erf(x); // Probably doing something wrong here
    double *outData = (double*)jl_array_data(out);
        // Print out the vector
    for(size_t i=0; i<4; i++)
        std::cout << outData[i] << ' ';
    std::cout << "\n";
    // Returns garbage
    // 4.94066e-324 0 0 6.91799e-310 
    return 0;

I would suggest not wrapping your array in a Julia array from the C side but let the Julia code handle the raw data. Cf Add array example by GunnarFarneback · Pull Request #3 · GunnarFarneback/DynamicallyLoadedEmbedding.jl · GitHub