# Compiling a library from a custom module

**URL:** <https://discourse.julialang.org/t/compiling-a-library-from-a-custom-module/44691>\
**Category:** General Usage\
**Created:** [August 10, 2020, 2:58pm UTC](https://discourse.julialang.org/t/compiling-a-library-from-a-custom-module/44691 "2020-08-10T14:58:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![maximilianpreisinger](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@maximilianpreisinger](https://discourse.julialang.org/u/maximilianpreisinger)\
**Post date:** [August 10, 2020, 2:58pm UTC](https://discourse.julialang.org/t/compiling-a-library-from-a-custom-module/44691/1 "2020-08-10T14:58:27Z")

</div>

Hi there!

I hope this is the right place to ask this question.  
I wrote a custom module “MOD”, and eventually I want to compile this module and its functions into a DLL, which functions I can call from a LabView program.

For the moment, I develop on Ubuntu 18.04. As a test, I tried to generate a \*.so file. I tested the module extensively with Julia 1.2, but I also run it with Julia 1.5 without any problems.

Now I saw that PackageCompiler can do what I want, and it even provides a description how to compile a library (sysimage) without PackageCompiler.

However, when I run

```julia
using PackageCompiler
activate .
include("src/MOD.jl")
using .MOD
create_sysimage(:MOD; sysimage_path="Sysimage.so", incremental=false, precompile_execution_file="build-tools/precompile-script.jl")

```

I get the error message: `ERROR: package(s) MOD not in project.`

Off course my module “MOD” is not handled by the package manager, but it is a module defined in the file src/MOD.jl which looks a bit like this:

```julia
module MOD

using DataFrames;
using LinearAlgebra: pinv
using DSP: conv
# ...

# Include functions
include("functions.jl")
# ...

end # module

```

What can I do that PackageCompiler recognizes my custom module?

Alternatively I tried to compile the library without PackageCompiler. In a first step to create the object file:  
`julia --startup-file=no --output-o Sysimage.o -J"/julia/dir/lib/julia/sys.so" custom_sysimage.jl`

where the script `custom_sysimage.jl` looks like

```julia
Base.init_depot_path()
Base.init_load_path()

include("./src/MOD.jl")
using .MOD

using DataFrames
using CSV
data = DataFrame(CSV.File("dummy.csv"))

MOD.run(data)

empty!(LOAD_PATH)
empty!(DEPOT_PATH)
data=0;
ans=0;

```

However, with this approach, I get the error:

```julia
ERROR: LoadError: could not load library "libfftw3.so.3"
libfftw3.so.3: Kann die Shared-Object-Datei nicht öffnen: Datei oder Verzeichnis nicht gefunden
(english: Cannot open the shared object file: file or directory not found)

```

However, when I start a julia session and do

```julia
include("./src/MOD.jl")
using .MOD

using DataFrames
using CSV
data = DataFrame(CSV.File("dummy.csv"))

MOD.run(data)

```

It runs without any error message.

All these examples were performed with Julia 1.5.

Can anybody guide me what is going wrong and how I can manage to compile these functions into a .\*so and finally into a DLL object? Currently I have no clue where I should start.

Furthermore, if I have some mistakes in my design, and it should be designed in some other way in order to reach my goal, please let me know!

---

<div class="post-metadata">

**Author:** ![maximilianpreisinger](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@maximilianpreisinger](https://discourse.julialang.org/u/maximilianpreisinger)\
**Post date:** [August 11, 2020, 10:41am UTC](https://discourse.julialang.org/t/compiling-a-library-from-a-custom-module/44691/2 "2020-08-11T10:41:16Z")

</div>

I tried to include

```julia
using Pkg
pkg"activate ."

```

in the custom\_sysimage file, because I became aware that I worked in the @v1.5 environment, and not in the local environment (although this should not change much, because I have all necessary packages installed in the @v1.5 environment also). However, these lines generate the following error:

```julia
ERROR: LoadError: ArgumentError: Package Pkg not found in current path:
- Run `import Pkg; Pkg.add("Pkg")` to install the Pkg package.

```

That is strange. using CSV and using DataFrames work, but using Pkg does not work…

As a second attempt, I omitted the flag “–startup-file=no” (because I didn’t really know why it should be important to not use the startup file for the system image generation), but I still get the error, that “libfftw3.so.3” could not be found. This library belongs to the FFTW package, which is a dependency of the DSP package.

However, when I simply run the command without the --output-o flag, everything runs without an error (however, no Sysimage is created off course…)

---

<div class="post-metadata">

**Author:** ![maximilianpreisinger](https://avatars.discourse-cdn.com/v4/letter/m/a3d4f5/32.png) [@maximilianpreisinger](https://discourse.julialang.org/u/maximilianpreisinger)\
**Post date:** [August 11, 2020, 4:48pm UTC](https://discourse.julialang.org/t/compiling-a-library-from-a-custom-module/44691/3 "2020-08-11T16:48:44Z")

</div>

Just to let people with the same problem know: It is really a mess and a never ending storry, to get this working in the way I want to…

I am using now ZeroMQ to communicate and transfer data between Julia and LabView.
