# Calling functions defined a custom module when embeded in C

**URL:** https://discourse.julialang.org/t/calling-functions-defined-a-custom-module-when-embeded-in-c/8918
**Category:** Community
**Tags:** question
**Created:** [February 8, 2018, 6:45am UTC](https://discourse.julialang.org/t/calling-functions-defined-a-custom-module-when-embeded-in-c/8918 "2018-02-08T06:45:17Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![pemryan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pemryan/32/1237_2.png) [@pemryan](https://discourse.julialang.org/u/pemryan)
#### Post date: [February 8, 2018, 6:45am UTC](https://discourse.julialang.org/t/calling-functions-defined-a-custom-module-when-embeded-in-c/8918/1 "2018-02-08T06:45:17Z")

</div>

hello julia hackers! Could you help me on calling functions defined a custom module in C?  
I’ve tried:

```julia
jl_eval_string("using mymodule");
jl_function_t* func = jl_get_function(jl_main_module, "myfunction");

```

this works as expected. While

```julia
    jl_sym_t* sym = jl_symbol("mymodule");
    jl_module_t* mymod = jl_new_module(sym);
    jl_module_using(jl_main_module, mymod);
    jl_function_t* func = jl_get_function(jl_main_module, "myfunction");

```

always returns null. What’s the correct way to express ‘using mymodule’ in C functions?

I’m doing this on Windows7 MSVC 2015.

```julia
Julia Version 0.6.2
Commit d386e40c17* (2017-12-13 18:08 UTC)
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: Intel(R) Core(TM) i5-4570 CPU @ 3.20GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)

```

Thank you in advance.  
pem

---

<div class="post-metadata">

### Author: ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)
#### Post date: [February 8, 2018, 6:59am UTC](https://discourse.julialang.org/t/calling-functions-defined-a-custom-module-when-embeded-in-c/8918/2 "2018-02-08T06:59:13Z")

</div>

> [@pemryan](#):
>
> jl\_sym\_t\* sym = jl\_symbol(“mymodule”);  
> jl\_module\_t\* mymod = jl\_new\_module(sym);

Won’t that simply create a new (empty) module?  
The `jl_module_using` call will simply use that empty module, IIUC.

---

<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: [February 8, 2018, 6:46pm UTC](https://discourse.julialang.org/t/calling-functions-defined-a-custom-module-when-embeded-in-c/8918/3 "2018-02-08T18:46:49Z")

</div>

> [@pemryan](#):
>
> always returns null. What’s the correct way to express ‘using mymodule’ in C functions?

`jl_eval_string("using mymodule")` basically.

I don’t think there’s an API for it. There could be, though given how easy it is to construct this kind of API yourself it certainly won’t be a high priority.

Like `pypy`, the recommended way to use julia functions in julia is to make your own API. You can create a julia function `using_module(name) = eval(:(using $name))` (e.g. with `jl_eval_string`) and just call that function in C. You can also construct the `Expr` (i.e. `jl_expr_t*`) and eval that.
