# Symbol not found when importing Fortran library within custom Package

**URL:** <https://discourse.julialang.org/t/symbol-not-found-when-importing-fortran-library-within-custom-package/80063>\
**Category:** General Usage\
**Tags:** question\
**Created:** [April 26, 2022, 1:58pm UTC](https://discourse.julialang.org/t/symbol-not-found-when-importing-fortran-library-within-custom-package/80063 "2022-04-26T13:58:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![cjproud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjproud/32/38494_2.png) [@cjproud](https://discourse.julialang.org/u/cjproud)\
**Post date:** [April 26, 2022, 1:58pm UTC](https://discourse.julialang.org/t/symbol-not-found-when-importing-fortran-library-within-custom-package/80063/1 "2022-04-26T13:58:25Z")

</div>

I’m importing compiled Fortran code as a shared library within a custom package I have created. However, when I call a Fortran function from my module within Python using JuliaCall ([GitHub - cjdoris/PythonCall.jl: Python and Julia in harmony.](https://github.com/cjdoris/PythonCall.jl)) and Ccall I get a symbol not found error. My module looks like this:

```julia
module Simulation
    using Libdl
    Libdl.dlopen("FortranFunctions", RTLD_LAZY | RTLD_DEEPBIND | RTLD_GLOBAL)
    include("julia_code_that_calls_fortran.jl")

```

is this the proper way to import a shared library within a module? I’m calling it in Python using JuliaCall via:

```julia
 from juliacall import Main as jl
      jl.seval("using Simulation")
     jl.Simulation.*ccall function within julia_code_that_calls_fortran.jl* (Pseudocode)

```

---

<div class="post-metadata">

**Author:** ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)\
**Post date:** [April 26, 2022, 2:23pm UTC](https://discourse.julialang.org/t/symbol-not-found-when-importing-fortran-library-within-custom-package/80063/2 "2022-04-26T14:23:25Z")

</div>

I imagine the dlopen has to be inside ` __init__ ()` [Modules · The Julia Language](https://docs.julialang.org/en/v1/manual/modules/#Module-initialization-and-precompilation). Another way would be to build your fortran library with [GitHub - JuliaPackaging/BinaryBuilder.jl: Binary Dependency Builder for Julia](https://github.com/JuliaPackaging/BinaryBuilder.jl) and add it to [GitHub - JuliaPackaging/Yggdrasil: Collection of builder repositories for BinaryBuilder.jl](https://github.com/JuliaPackaging/Yggdrasil)

---

<div class="post-metadata">

**Author:** ![cjproud](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjproud/32/38494_2.png) [@cjproud](https://discourse.julialang.org/u/cjproud)\
**Post date:** [April 28, 2022, 12:23pm UTC](https://discourse.julialang.org/t/symbol-not-found-when-importing-fortran-library-within-custom-package/80063/3 "2022-04-28T12:23:31Z")

</div>

Thanks, that worked! I’ve looked at the docs and can’t really figure out why that worked however……do you have a better explanation?

---

<div class="post-metadata">

**Author:** ![gbaraldi](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gbaraldi/32/22101_2.png) [@gbaraldi](https://discourse.julialang.org/u/gbaraldi)\
**Post date:** [April 28, 2022, 4:38pm UTC](https://discourse.julialang.org/t/symbol-not-found-when-importing-fortran-library-within-custom-package/80063/4 "2022-04-28T16:38:10Z")

</div>

Basically, what you had written would try to run at precompile time not at actual runtime when the user wrote `using MyPackage` . ` __init__ ()` serves the exact purpose you had, which is to run something when the user calls `using MyPackage`. So it could have the opening of the shared library, some initialization steps that could be needed etc.
