# Import custom Julia module from C & use it

**URL:** https://discourse.julialang.org/t/import-custom-julia-module-from-c-use-it/43979
**Category:** General Usage
**Tags:** embedding
**Created:** [July 30, 2020, 1:42pm UTC](https://discourse.julialang.org/t/import-custom-julia-module-from-c-use-it/43979 "2020-07-30T13:42:28Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Clonkk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/clonkk/32/20088_2.png) [@Clonkk](https://discourse.julialang.org/u/Clonkk)
#### Post date: [July 30, 2020, 1:42pm UTC](https://discourse.julialang.org/t/import-custom-julia-module-from-c-use-it/43979/1 "2020-07-30T13:42:28Z")

</div>

Hello,

I’m trying to import a local Julia module from C and call a function;  
but jl\_get\_function always return a null pointer.

I based my code on [this topic](https://discourse.julialang.org/t/calling-functions-defined-a-custom-module-when-embeded-in-c/8918) and [this SO question](https://stackoverflow.com/questions/55970064/calling-local-julia-package-from-c), but nothing I’ve tried worked.

This is the C-code :

```julia
  /* required: setup the Julia context */
  jl_init();

  {
    printf("include test.jl \n");
    jl_eval_string("Base.include(Main, \"./test.jl\")");
    // Tried both version with no success
    // jl_eval_string("include(\"./test.jl\")");
    printf("using custom_module \n");

    jl_eval_string("using custom_module");
    {
        printf("dummy \n");
        // Call easy function
        jl_function_t *dummy= jl_get_function(jl_main_module, "dummy");

        if (dummy != NULL)
        {
          printf("dummy is not null\n");
        }
        else
        {
          printf("dummy is null\n");
          jl_atexit_hook(0);
          return 0;
        }

        jl_call0(dummy);
        jl_atexit_hook(0);
        return 0;
    } 

```

This the julia file:

```julia
module custom_module 
  using LinearAlgebra

  function dummy()
    println("Hello world from dummy")
  end

  function testMeBaby(A)
    println(typeof(A))
    println(A)
    B = lmul!(10, A)
    println(B)
    println(size(B))
    println(ndims(B))
    return B
  end

  export testMeBaby
  export dummy
end

```

What am I missing or doing wrong here ?  
I’m using gcc 9.3.0 &nd Julia v1.4.2 with Ubuntu 20.04 inside WSL2.

Also Is there any restriction I should be aware of when executing Julia function from C ?

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [July 30, 2020, 1:53pm UTC](https://discourse.julialang.org/t/import-custom-julia-module-from-c-use-it/43979/2 "2020-07-30T13:53:26Z")

</div>

You are using `jl_eval_string` to run julia code, so you need to make sure that actually runs first. Either by just running the julia code, or check the status after calling `jl_eval_string`.

> [@Clonkk](#):
>
> ```julia
> jl_eval_string("using custom_module");
> 
> ```

`using .custom_module`

---

<div class="post-metadata">

### Author: ![Clonkk](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/clonkk/32/20088_2.png) [@Clonkk](https://discourse.julialang.org/u/Clonkk)
#### Post date: [July 30, 2020, 1:58pm UTC](https://discourse.julialang.org/t/import-custom-julia-module-from-c-use-it/43979/3 "2020-07-30T13:58:16Z")

</div>

Thanks for your help !

Putting a ".’ before the module name do work indeed.  
Why is it required ? Is it because it’s a local module ?

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [July 30, 2020, 2:08pm UTC](https://discourse.julialang.org/t/import-custom-julia-module-from-c-use-it/43979/4 "2020-07-30T14:08:02Z")

</div>

[Modules · The Julia Language](https://docs.julialang.org/en/v1/manual/modules/#Relative-and-absolute-module-paths-1) Not really “local”, but they are not toplevel.
