# How do I create a binary from .jl files?

**URL:** https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521
**Category:** New to Julia
**Created:** [May 5, 2022, 4:32am UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521 "2022-05-05T04:32:40Z")
**Posts on this page:** 15
**Page:** 2

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [May 5, 2022, 5:47pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/21 "2022-05-05T17:47:30Z")

</div>

> [@Raf](#):
>
> Julias’ binary compilation story is _very_ immature,

Well, PackageCompiler.jl is not immature at all.

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [May 5, 2022, 6:00pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/22 "2022-05-05T18:00:55Z")

</div>

Here are a few videos on how to use PackageCompiler.jl to create binary executables and shared libraries.

[![](https://global.discourse-cdn.com/julialang/original/3X/2/5/25d92fc8d496bba03c1793e16cb4c78a684e8de5.jpeg "JuliaCon 2020 | Shippable apps and custom sysimages with PackageCompiler.jl | Kristoffer Carlsson") ](https://www.youtube.com/watch?v=d7avhSuK2NA)

[![](https://global.discourse-cdn.com/julialang/original/3X/2/8/289d84c0fa90d31c7a8c783257bd157edc21e6f0.jpeg "Creating Shared Library Bundles with Package Compiler | K Carlsson, S Byrne, K Squire | JuliaCon2021") ](https://www.youtube.com/watch?v=c0IAP7NC2MU)

[![](https://global.discourse-cdn.com/julialang/original/3X/2/d/2d1c329f4cb9acf9dd28cba02c5d689fbe0e59bc.jpeg "Deep Dive: Creating Shared Libraries with PackageCompiler.jl | K Carlsson et al | JuliaCon2021") ](https://www.youtube.com/watch?v=7PAqOKwoUC8)

The documentation for this can be found below:

> **[Apps · PackageCompiler](https://julialang.github.io/PackageCompiler.jl/stable/apps.html)**
>
> Documentation for PackageCompiler.

As for the REPL, if you do not want to use for its interactive features, I would consider using it as a development tool that implements a compilation cache.

---

<div class="post-metadata">

### Author: ![Raf](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raf/32/3383_2.png) [@Raf](https://discourse.julialang.org/u/Raf)
#### Post date: [May 5, 2022, 6:44pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/23 "2022-05-05T18:44:47Z")

</div>

PackageCompiler is amazing. But it’s also slow and creates truly enormous binaries. If you’re used to compiling go there will be no comparison. We need to be honest about that so peoples expectations will match reality.

---

<div class="post-metadata">

### Author: ![Mason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mason/32/2423_2.png) [@Mason](https://discourse.julialang.org/u/Mason)
#### Post date: [May 5, 2022, 6:46pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/24 "2022-05-05T18:46:58Z")

</div>

Especially when the actual goal in this case appears to not be compilation but rather code organization.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [May 5, 2022, 8:21pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/25 "2022-05-05T20:21:18Z")

</div>

> [@Raf](#):
>
> But it’s also slow

Well, I am working on a C/C++ project with compilation times not below a few hours. Compared to that PackageCompiler is fast. And there is no need to run it after every change, I run it perhaps every other day and it takes never more than 15 minutes.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [May 5, 2022, 8:31pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/26 "2022-05-05T20:31:03Z")

</div>

> [@Mason](#):
>
> code organization

I am not using the .julia/dev folder. Instead, I have a repos folder where I check out my git projects. A complex Julia project usually consists of a number of related packages and (perhaps) a main project which is not a package. For me this looks like this:

```julia
ufechner@tuxedi:~/repos$ tree -d Kite*
KiteControllers.jl
├── data
├── doc
├── src
└── test
KiteModels.jl
├── bin
├── data
├── docs
│ ├── build
│ │ └── assets
│ │ └── themes
│ ├── data
│ └── src
│ └── assets
├── examples
├── src
└── test
KiteUtils.jl
├── data
├── docs
│ └── src
├── src
└── test
KiteViewer
├── data
├── doc
├── src
└── test
KiteViewers.jl
├── bin
├── data
├── examples
├── src
└── test

30 directories

```

---

<div class="post-metadata">

### Author: ![paulmelis](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/paulmelis/32/35063_2.png) [@paulmelis](https://discourse.julialang.org/u/paulmelis)
#### Post date: [May 5, 2022, 9:42pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/27 "2022-05-05T21:42:10Z")

</div>

> [@ufechner7](#):
>
> Well, I am working on a C/C++ project with compilation times not below a few hours. Compared to that PackageCompiler is fast. And there is no need to run it after every change, I run it perhaps every other day and it takes never more than 15 minutes.

I’m curious how large the actual C++ code is and if parallel compilation is used? I’ve only ever had one multi-hour compilation (and have built quite a few C++ packages over the years) and that’s ParaView, which is a humongous build when its dependencies are included. Not trying to say you don’t have a multi-hour build, just trying to understand what kind of project you’re refering to.

> [@ufechner7](#):
>
> And there is no need to run it after every change, I run it perhaps every other day and it takes never more than 15 minutes.

Edit: this I don’t understand. C++ builds can easily to incremental compilation, saving lots of time, while with PackageCompiler that seems almost impossible (unless you build separate sysimages for subsets manually).

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [May 5, 2022, 10:02pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/28 "2022-05-05T22:02:40Z")

</div>

> [@paulmelis](#):
>
> I’m curious how large the actual C++ code is and if parallel compilation is used?

We are using Buildroot to create a system image for an embedded system. We have a fast machine with 16 cores and use ccache. And incremental builds often do NOT work if you use Buildroot (sometimes they work).

> [@paulmelis](#):
>
> Edit: this I don’t understand.

Well, I use PackageCompiler mainly to compile the packages I am currently NOT working at. The package I currently work at gets pre-compiled on load and compiled when running a function, but this usually only takes a few seconds, worst case 10 seconds.

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [May 5, 2022, 10:47pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/29 "2022-05-05T22:47:58Z")

</div>

> [@DWSchulze](#):
>
> Each time I’ve tried Julia I find things that break from one minor version to another.

Not my experience, and from what I hear having things break with minor versions is very rare (if it in fact happens at all).

> [@DWSchulze](#):
>
> And lacking a decent build chain and dependency management looks pretty immature.

Sorry, this is nonsense. Julia has great dependency management, and if you insist on building a static executable, you are probably not using the language efficiently.

---

<div class="post-metadata">

### Author: ![Henrique\_Becker](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/henrique_becker/32/15443_2.png) [@Henrique\_Becker](https://discourse.julialang.org/u/Henrique_Becker)
#### Post date: [May 6, 2022, 12:27am UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/30 "2022-05-06T00:27:15Z")

</div>

> [@DWSchulze](#):
>
> I had just assumed that Julia was a mature language being at v 1.7+. Thanks for setting me straight on that.

No need to be inflammatory. I use Julia on my PhD and used it for my internship at Amazon (as an Applied Scientist). I consider it to be a mature language. It is just not designed with compilation to a binary in mind, as many other languages were not. Even so, it has packages that allow for it if it is strictly necessary.

---

<div class="post-metadata">

### Author: ![DWSchulze](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dwschulze/32/35968_2.png) [@DWSchulze](https://discourse.julialang.org/u/DWSchulze)
#### Post date: [May 6, 2022, 8:31pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/31 "2022-05-06T20:31:30Z")

</div>

@PetrKryslUCSD

All I’ve seen in example material are things like

] add MLDatasets  
using MLDatasets

with no versioning at all. No one seems to mention dependency management. I’ve yet to hear any Julia intro material mention transitive dependencies.

---

<div class="post-metadata">

### Author: ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)
#### Post date: [May 6, 2022, 8:35pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/32 "2022-05-06T20:35:14Z")

</div>

> [@DWSchulze](#):
>
> no versioning at all

Example 4 here [3. Managing Packages · Pkg.jl](https://pkgdocs.julialang.org/v1/managing-packages/#Adding-packages)

> [@DWSchulze](#):
>
> dependency management

Perhaps [3. Managing Packages · Pkg.jl](https://pkgdocs.julialang.org/v1/managing-packages/#conflicts)  
and [6. Compatibility · Pkg.jl](https://pkgdocs.julialang.org/v1/compatibility/)

---

<div class="post-metadata">

### Author: ![PetrKryslUCSD](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petrkryslucsd/32/215825_2.png) [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)
#### Post date: [May 6, 2022, 9:05pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/33 "2022-05-06T21:05:52Z")

</div>

The versioning may be done via Project.toml/Manifest.toml. It is not necessarily spelled out in the command line.

---

<div class="post-metadata">

### Author: ![mkitti](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkitti/32/12459_2.png) [@mkitti](https://discourse.julialang.org/u/mkitti)
#### Post date: [May 6, 2022, 10:34pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/34 "2022-05-06T22:34:03Z")

</div>

> [@PetrKryslUCSD](#):
>
> It is not necessarily spelled out in the command line.

If you wanted to do spell it out on the command line, that is also very possible by appending `@major.minor.patch`. The default is to try to obtain the latest version that is also compatible with your current environment settings.

```julia
(@v1.7) pkg> ?add
  add [--preserve=<opt>] pkg[=uuid] [@version] [#rev] ...

  Add package pkg to the current project file. If pkg could refer to multiple different packages, specifying uuid
  allows you to disambiguate. @version optionally allows specifying which versions of packages to add. Version
  specifications are of the form @1, @1.2 or @1.2.3, allowing any version with a prefix that matches, or ranges
  thereof, such as @1.2-3.4.5. A git revision can be specified by #branch or #commit.

  If a local path is used as an argument to add, the path needs to be a git repository. The project will then track
  that git repository just like it would track a remote repository online. If the package is not located at the top of
  the git repository, a subdirectory can be specified with path:subdir/path.

  Pkg resolves the set of packages in your environment using a tiered approach. The --preserve command line option
  allows you to key into a specific tier in the resolve algorithm. The following table describes the command line
  arguments to --preserve (in order of strictness).

  Argument Description
  –––––––– –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
  all Preserve the state of all existing dependencies (including recursive dependencies)
  direct Preserve the state of all existing direct dependencies
  semver Preserve semver-compatible versions of direct dependencies
  none Do not attempt to preserve any version information
  tiered Use the tier which will preserve the most version information (this is the default)

  │ Julia 1.5
  │
  │ Subdirectory specification requires at least Julia 1.5.

  Examples

  pkg> add Example
  pkg> add --preserve=all Example
  pkg> add Example@0.5
  pkg> add Example#master
  pkg> add Example#c37b675
  pkg> add https://github.com/JuliaLang/Example.jl#master
  pkg> add git@github.com:JuliaLang/Example.jl.git
  pkg> add Example=7876af07-990d-54b4-ab0e-23690620f79a

```

See the Pkg.jl links above for more information.

---

<div class="post-metadata">

### Author: ![ufechner7](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ufechner7/32/51363_2.png) [@ufechner7](https://discourse.julialang.org/u/ufechner7)
#### Post date: [May 11, 2022, 10:16pm UTC](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521/36 "2022-05-11T22:16:22Z")

</div>

Well, in the last year I had twice the situation that a specific package version was broken and I had to manually select an older version. This happened with StaticArrays and with Rotatations…

[Previous page](https://discourse.julialang.org/t/how-do-i-create-a-binary-from-jl-files/80521.md?page=1)
