# Including a binary (a "\*.so") with a package?

**URL:** <https://discourse.julialang.org/t/including-a-binary-a-so-with-a-package/101626>\
**Category:** New to Julia\
**Tags:** c\
**Created:** [July 14, 2023, 1:36pm UTC](https://discourse.julialang.org/t/including-a-binary-a-so-with-a-package/101626 "2023-07-14T13:36:57Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [July 14, 2023, 1:36pm UTC](https://discourse.julialang.org/t/including-a-binary-a-so-with-a-package/101626/1 "2023-07-14T13:36:57Z")

</div>

We have a vendor C API that we are currently trying to wrap in Julia. I just have their headers and a dynamic library. Presently I am using `] generate` to create new projects because of the way that our source is stored. We store everyone’s work in one gigantic git repo\[1\], so I am not sure that I can use PkgTemplates in a “no git repo” situation.

I looked around at other projects, like [Interpolations](https://github.com/JuliaMath/Interpolations.jl) and thought that a subdirectory like `./ext` might be appropriate to store the `*.so` in? After that, I was thinking of hard-coding the path to the `*.so` into a global variable in the main Julia file:

src/NEAT.jl:

```julia
neatlib::String = "../ext/libneat.so"

function neatthing()
    @ccall neatlib.do_neat()::Cvoid
end

```

* * *

1. NOT my idea, and sooner or later I’ll convince “them” to change it.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [July 14, 2023, 4:26pm UTC](https://discourse.julialang.org/t/including-a-binary-a-so-with-a-package/101626/2 "2023-07-14T16:26:30Z")

</div>

> **[GitHub - JuliaPackaging/BinaryBuilder.jl: Binary Dependency Builder for Julia](https://github.com/JuliaPackaging/BinaryBuilder.jl)**
>
> Binary Dependency Builder for Julia. Contribute to JuliaPackaging/BinaryBuilder.jl development by creating an account on GitHub.

> [@frylock](#):
>
> I looked around at other projects, like [Interpolations](https://github.com/JuliaMath/Interpolations.jl) and thought that a subdirectory like `./ext` might be appropriate to store the `*.so` in?

I’m not sure how you got that idea from `Interpolations` as it doesn’t ship any shared library.

---

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [July 14, 2023, 4:27pm UTC](https://discourse.julialang.org/t/including-a-binary-a-so-with-a-package/101626/3 "2023-07-14T16:27:43Z")

</div>

It has an `./ext` folder though, seemed reasonable to put external things in a directory named like that.

---

<div class="post-metadata">

**Author:** ![giordano](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/giordano/32/2166_2.png) [@giordano](https://discourse.julialang.org/u/giordano)\
**Post date:** [July 14, 2023, 4:28pm UTC](https://discourse.julialang.org/t/including-a-binary-a-so-with-a-package/101626/4 "2023-07-14T16:28:46Z")

</div>

That’s for [Package Extensions](https://julialang.org/blog/2023/04/julia-1.9-highlights/#package_extensions)

---

<div class="post-metadata">

**Author:** ![frylock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/frylock/32/50213_2.png) [@frylock](https://discourse.julialang.org/u/frylock)\
**Post date:** [July 14, 2023, 4:30pm UTC](https://discourse.julialang.org/t/including-a-binary-a-so-with-a-package/101626/5 "2023-07-14T16:30:22Z")

</div>

I guess in that case, perhaps just right alongside the `*.jl` files?

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 14, 2023, 4:35pm UTC](https://discourse.julialang.org/t/including-a-binary-a-so-with-a-package/101626/6 "2023-07-14T16:35:31Z")

</div>

To follow up, let me explain that `.so` files are usually distributed in a [package artifact](https://pkgdocs.julialang.org/v1/artifacts/#Artifacts.toml-files-1), and in turn these artifacts are usually listed in a [JLL package](https://docs.binarybuilder.org/stable/jll/), which you then list as a dependency of your Julia package. This way, when you load your Julia package, the JLL automatically grabs the correct `.so` file for the current platform.

JLL packages and their artifacts, in turn, are usually generated by a BinaryBuilder script. The easiest way to do this, at least for open-source software, is to make a pull request to the [Yggdrasil repository](https://github.com/JuliaPackaging/Yggdrasil), which will automatically run your script to generate cross-compiled binaries for all supported Julia platforms, and will then automatically upload and register the JLL package.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 14, 2023, 4:42pm UTC](https://discourse.julialang.org/t/including-a-binary-a-so-with-a-package/101626/7 "2023-07-14T16:42:34Z")

</div>

> [@stevengj](#):
>
> The easiest way to do this, at least for open-source software, is to make a pull request to the [Yggdrasil repository](https://github.com/JuliaPackaging/Yggdrasil), which will automatically run your script to generate cross-compiled binaries for all supported Julia platforms, and will then automatically upload and register the JLL package.

Note that BinaryBuilder and Yggdrasil also work for non open-source software that is provided by a vendor merely as a collection of `.so` files. See, for example the [script to build a JLL for MKL](https://github.com/JuliaPackaging/Yggdrasil/blob/master/M/MKL/build_tarballs.jl).
