# How to use juliac.jl?

**URL:** <https://discourse.julialang.org/t/how-to-use-juliac-jl/123024>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 24, 2024, 7:31pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024 "2024-11-24T19:31:03Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![MilesCranmer](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/milescranmer/32/21070_2.png) [@MilesCranmer](https://discourse.julialang.org/u/MilesCranmer)\
**Post date:** [November 24, 2024, 7:31pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/1 "2024-11-24T19:31:03Z")

</div>

I watched [this talk](https://www.youtube.com/watch?v=hUxnLunOU4w) on juliac which I am eager to try out but I can’t figure out how. I looked through the dev docs and the relevant [PR](https://github.com/JuliaLang/julia/pull/55047), but no such luck, so am posting here.

To get started I ran this:

```bash
juliaup update nightly
juliaup default nightly

```

Then, the first (naive) thing I tried was the exact syntax from the talk

```julia
# main.jl
module MyApp
Base.@ccallable function myfunc()::Cint
    println(Core.stdout, "Hello, world!")
    return 0
end
end

```

```bash
julia juliac.jl --output-exe main --trim main.jl

```

to which I realised that `juliac.jl` is an actual file somewhere and not a special subcommand. I found it sitting in `~/.julia/juliaup/julia-nightly/share/julia/juliac.jl` so went with that. Here’s the first error:

```bash
> julia ~/.julia/juliaup/julia-nightly/share/julia/juliac.jl \
    --output-exe main --trim main.jl

ERROR: julia: --trim is an experimental feature, you must enable it with --experimental

Failed to compile main.jl

```

Ok, so I tried adding `--experimental` on the end:

```bash
> julia ~/.julia/juliaup/julia-nightly/share/julia/juliac.jl \
    --output-exe main --trim --experimental main.jl

Unexpected argument `--experimental`

```

Weird. Where should `--experimental` go? Maybe as an argument to `julia` itself? This is what I tried next:

```julia
> julia --experimental \
    ~/.julia/juliaup/julia-nightly/share/julia/juliac.jl \
    --output-exe main --trim main.jl

ERROR: julia: --trim is an experimental feature, you must enable it with --experimental

Failed to compile main.jl

```

Even weirder. Maybe I am supposed to pass `--trim` to the julia binary too?

```julia
> julia --experimental --trim \
    ~/.julia/juliaup/julia-nightly/share/julia/juliac.jl \
    --output-exe main main.jl

ld: warning: ignoring duplicate libraries: '-ljulia'
Undefined symbols for architecture arm64:
  "_main", referenced from:
      <initial-undefines>
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Compilation failed.

```

I also tried putting all the flags in both spots, but got back to the first error:

```julia
> julia --experimental --trim \
    ~/.julia/juliaup/julia-nightly/share/julia/juliac.jl \
    --output-exe main --trim main.jl

ERROR: julia: --trim is an experimental feature, you must enable it with --experimental

Failed to compile main.jl

```

Does anybody know how to get this cool new feature working? Maybe it doesn’t yet support arm64, or perhaps it’s not compatible with juliaup, or perhaps I just need to do something like fix my `$LD_LIBRARY_PATH` to point to the right julia library files?

* * *

[disclaimer: I understand juliac is highly experimental etc and don’t expect full support on it yet; just was curious to check it out!]

---

<div class="post-metadata">

**Author:** ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)\
**Post date:** [November 24, 2024, 7:37pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/2 "2024-11-24T19:37:32Z")

</div>

See [pass experimental flag in juliac script by baggepinnen · Pull Request #56602 · JuliaLang/julia · GitHub](https://github.com/JuliaLang/julia/pull/56602)

For general juliac setup you might find [Runic.jl/juliac at master · fredrikekre/Runic.jl · GitHub](https://github.com/fredrikekre/Runic.jl/tree/master/juliac) useful.

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [November 24, 2024, 8:04pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/3 "2024-11-24T20:04:15Z")

</div>

Oh @MilesCranmer , you may find this write-up I made earlier interesting: [Pushing the Limits of Small Binary Creation](https://discourse.julialang.org/t/pushing-the-limits-of-small-binary-creation/120989)

Here is the reproducible repo I set-up for that post: [GitHub - TheCedarPrince/InteroperableJuliaBinaries: Experiments in making Julia binaries interoperable within other language C interfaces.](https://github.com/TheCedarPrince/InteroperableJuliaBinaries)

Also, something I haven’t had a chance to explore is this tweet from @jbytecode :

> <https://x.com/mhsatman/status/1858564496437936460>

Seems like there may be some regressions compared to my last effort. I’d be curious what you find out, Miles!

---

<div class="post-metadata">

**Author:** ![TheCedarPrince](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thecedarprince/32/17323_2.png) [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Post date:** [November 24, 2024, 8:05pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/4 "2024-11-24T20:05:25Z")

</div>

> [@MilesCranmer](#):
>
> or perhaps I just need to do something like fix my `$LD_LIBRARY_PATH` to point to the right julia library files?

Also, in my GitHub repo I linked, I discuss a little bit about `LD_PATH`ing as at the time, something was breaking but I found a workaround.

---

<div class="post-metadata">

**Author:** ![uwestoehr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uwestoehr/32/216201_2.png) [@uwestoehr](https://discourse.julialang.org/u/uwestoehr)\
**Post date:** [April 9, 2025, 1:18pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/5 "2025-04-09T13:18:37Z")

</div>

Coming from [this thread](https://discourse.julialang.org/t/how-to-create-standalone-applications-for-windows-with-a-ui-in-julia-1-11-or-1-12/127823/14), I need to compile my Julia module .jl file to a DLL that I can later include in other programs.

I heard that juliac could do this. Can anybody please give me a step by step instruction on how to compile a Julia module to a DLL? I already downloaded Julia 1.12 beta and I am willing to try out experimental things. But I am a new user thus need a step by step instruction.

---

<div class="post-metadata">

**Author:** ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)\
**Post date:** [April 11, 2025, 8:25am UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/6 "2025-04-11T08:25:24Z")

</div>

Here is the link of my playground repository that includes examples from the very early times of the `juliac` compiler:

> **[GitHub - jbytecode/juliac: Examples for Julia's generating small binary...](https://github.com/jbytecode/juliac)**
>
> Examples for Julia's generating small binary executables and libraries feature.

This repo includes a link for my initial blogpost, main discourse discussion, and my playground with examples of generating executables and shared libraries.

I copied and pasted the file `args2.jl` from somewhere else, but I don’t remember the link of this repo. Thank you for the author of this file, indeed, it’s very helpful on parsing command line arguments.

I know the examples hosted in the repo are quite basic and minimal. I just want to share my experiments for those who want to start working with `juliac`.

Edit: I’ve just found the aforementioned reference and added it to required files.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [April 11, 2025, 8:53am UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/7 "2025-04-11T08:53:53Z")

</div>

At this point I would say that `juliac` is still at the stage where it is a challenge for experienced Julia users to do non-trivial things (and sometimes trivial too) and we’re still trying to figure out what the step by steps even are beyond the most basic examples.

---

<div class="post-metadata">

**Author:** ![markusgumbel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/markusgumbel/32/49707_2.png) [@markusgumbel](https://discourse.julialang.org/u/markusgumbel)\
**Post date:** [April 11, 2025, 11:40am UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/8 "2025-04-11T11:40:39Z")

</div>

I found this blog very helpful: [https://jbytecode.github.io/juliac/](https://jbytecode.github.io/juliac/)  
It gives a step-by-step tutorial and worked with Julia 1.12 beta.

---

<div class="post-metadata">

**Author:** ![uwestoehr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uwestoehr/32/216201_2.png) [@uwestoehr](https://discourse.julialang.org/u/uwestoehr)\
**Post date:** [April 12, 2025, 12:59am UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/9 "2025-04-12T00:59:56Z")

</div>

> [@markusgumbel](#):
>
> [juliac](https://jbytecode.github.io/juliac/)  
> It gives a step-by-step tutorial and worked with Julia 1.12 beta.

I tried it and it does not work. I installed Julia 1.12 beta1 and when i try then

```julia
julia juliac.jl

```

it cannot find the file juliac.jl. So one has to specify the complete paths. In my case it would be

```julia
J:\\Julia-1.12\\bin\julia.exe J:\\Julia-1.12\\share\\julia\\juliac.jl --output-exe hello --trim D:\\usti\\Julia\\JuliaC\\helloworld.jl

```

and the content of helloworld.jl is just:

```julia
module HelloWorld

Base.@ccallable function main()::Cint
    println(Core.stdout, "Hello, World!")
    return 0
end
end # End of module HelloWorld 

```

The error I get is

```julia
LoadError: IOError: could not spawn `cc -std=gnu11 '-IJ:\Julia-1.12\include\julia' -g -c -o 'C:\Users\Uwe\AppData\Local\Temp\jl_UOF4T3\init.a' 'C:\Users\Uwe\AppData\Local\Temp\jl_UOF4T3\init.c'`: no such file or directory (ENOENT)

```

But I have no info why init.a was not created.

I also wonder how I specify the path to the C compiler. I have Microsoft Visual Studio as C/C++ compiler. But how to I tell Julia its path?

---

<div class="post-metadata">

**Author:** ![Ininterrompue](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ininterrompue/32/5594_2.png) [@Ininterrompue](https://discourse.julialang.org/u/Ininterrompue)\
**Post date:** [April 12, 2025, 1:19am UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/10 "2025-04-12T01:19:30Z")

</div>

I got the compiler working by following the steps [here](https://code.visualstudio.com/docs/cpp/config-mingw#_installing-the-mingww64-toolchain) to install the MinGW-w64 toolchain.

If you’re on Windows, juliac will probably error. [Someone else](https://github.com/JuliaLang/julia/issues/57941) has been able to reproduce an exception I’ve been seeing while using `--trim`.

---

<div class="post-metadata">

**Author:** ![uwestoehr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uwestoehr/32/216201_2.png) [@uwestoehr](https://discourse.julialang.org/u/uwestoehr)\
**Post date:** [April 12, 2025, 1:39am UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/11 "2025-04-12T01:39:09Z")

</div>

Ah, Juliac.jl has hardcoded the compiler `cc`,  
for example in this line:

```julia
run(`cc $(cflags) -g -c -o $init_path $initsrc_path`)

```

Instead of `cc`, for the Visual Studio compiler, there must be probably the full path to the cl.exe.

However, why is a certain compiler hardcoded? There should be an option to specify the compiler.  
I would even say, without this option juliac is not very useful. For desktop apps Windows is the main platform therefore a Linux-specific compiler-setting cannot be hardcoded.

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [April 12, 2025, 8:46am UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/12 "2025-04-12T08:46:30Z")

</div>

It would certainly be better if Visual Studio could also be used and worked out of the box but I don’t agree that the current compiler is Linux-specific. MinGW-w64 is after all used to compile Julia and all C/C++ binary dependencies on Windows.

At some point when `juliac` is more mature than an experimental feature of a beta release, I’m sure things will be smoother, but for now there’s need for people to try it out, figure out how to get things working and make pull requests to improve the tools.

---

<div class="post-metadata">

**Author:** ![uwestoehr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uwestoehr/32/216201_2.png) [@uwestoehr](https://discourse.julialang.org/u/uwestoehr)\
**Post date:** [April 12, 2025, 1:51pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/13 "2025-04-12T13:51:22Z")

</div>

> [@GunnarFarneback](#):
>
> I don’t agree that the current compiler is Linux-specific. MinGW-w64 is after all

I have MinGW-w64 installed (via [GitHub - niXman/mingw-builds-binaries: MinGW-W64 compiler binaries](https://github.com/niXman/mingw-builds-binaries)) but as juliac hardcodes `cc`, it won’t be used.

I first had to manually add the bath to the cc.exe of MinGW to Windows’ PATH environment variable.

So there should be something done, either an option to juliac to specify the path to the compiler executable or Julia’s installer gets an option to install MinGW and then sets up the environment variables directly.

---

<div class="post-metadata">

**Author:** ![ShalokShalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shalokshalom/32/52462_2.png) [@ShalokShalom](https://discourse.julialang.org/u/ShalokShalom)\
**Post date:** [May 7, 2025, 5:26pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/14 "2025-05-07T17:26:25Z")

</div>

Is Juliac supposed to be the solution for Web Assembly as well?

---

<div class="post-metadata">

**Author:** ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)\
**Post date:** [May 7, 2025, 6:10pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/15 "2025-05-07T18:10:37Z")

</div>

In its current state, the compiled binary executable or library depends on the shared libraries of the Julia runtime. Essentially, the output relies on a significant portion of the Julia installation, which makes it difficult to bring everything into a web browser. I believe static trimmed compilation could solve this problem, but I’m not sure if it’s currently planned. I’m also uncertain which parts of Julia can be trimmed and how large the output would be once trimmed static compilation becomes a reality.

---

<div class="post-metadata">

**Author:** ![ShalokShalom](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shalokshalom/32/52462_2.png) [@ShalokShalom](https://discourse.julialang.org/u/ShalokShalom)\
**Post date:** [May 13, 2025, 7:15pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/16 "2025-05-13T19:15:27Z")

</div>

Other than that, its fine? I am mostly interested about using WebAssembly on WASI compatible runtimes on the desktop.

A couple of projects like Armory3D, Zed and Lapce use it as extension format.

Thanks a lot!

---

<div class="post-metadata">

**Author:** ![gitboy16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gitboy16/32/24906_2.png) [@gitboy16](https://discourse.julialang.org/u/gitboy16)\
**Post date:** [May 14, 2025, 7:51am UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/17 "2025-05-14T07:51:33Z")

</div>

@jbytecode , the example shown in your repo are very useful. Thank you for sharing. Would you have an example of code that return vectors or matrices? I am trying to build a dll/so that do vector/matrice operations and I am not sure exactly how to return the result right.

---

<div class="post-metadata">

**Author:** ![jbytecode](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jbytecode/32/17719_2.png) [@jbytecode](https://discourse.julialang.org/u/jbytecode)\
**Post date:** [May 14, 2025, 6:38pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/18 "2025-05-14T18:38:52Z")

</div>

Who is the caller? Are you trying to compile your Julia code as a shared library and then call a Julia function from within C? If so, I think doing the allocations in the caller side and passing the result container (possibly an array) as a function argument is a better way rather than returning an object which is marked by the garbage collector. I haven’t tried such a case before. If the case is calling Julia compiled code from within Julia, It would be regular. What is the problem that you encountered?

---

<div class="post-metadata">

**Author:** ![gitboy16](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gitboy16/32/24906_2.png) [@gitboy16](https://discourse.julialang.org/u/gitboy16)\
**Post date:** [May 14, 2025, 7:44pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/19 "2025-05-14T19:44:48Z")

</div>

Yes that is exactly what I am trying to do, i.e. compile julia code as shared library and then call the function from within C. An example is done in thebl following repo:

> **[GitHub - terasakisatoshi/libcalcpi\_juliac: \`juliac\` in action](https://github.com/terasakisatoshi/libcalcpi_juliac)**
>
> \`juliac\` in action

Question is how to do the same but with a matrix or a vector?  
What are the function signatures so that the matrice/vector can be passed between C and Julia and vice versa?

---

<div class="post-metadata">

**Author:** ![GunnarFarneback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gunnarfarneback/32/1827_2.png) [@GunnarFarneback](https://discourse.julialang.org/u/GunnarFarneback)\
**Post date:** [May 14, 2025, 8:37pm UTC](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024/20 "2025-05-14T20:37:52Z")

</div>

There’s a difficult way and an easy way.

The difficult way is to pass Julia objects between Julia and C. This involves searching [julia.h](https://github.com/JuliaLang/julia/blob/master/src/julia.h) for functions and types involved in manipulating the objects, and figuring out how to use them.

The easy way is to pass memory pointers and size information separately, and preferably allocate the memory on the C side and use `unsafe_wrap` on the Julia side to create a Julia array. You can find an example in [DynamicallyLoadedEmbedding.jl/src/julia\_cfunctions.jl at master · GunnarFarneback/DynamicallyLoadedEmbedding.jl · GitHub](https://github.com/GunnarFarneback/DynamicallyLoadedEmbedding.jl/blob/master/src/julia_cfunctions.jl#L16-L31) (although with `unsafe_load`/`unsafe_store!` rather than `unsafe_wrap`).

[Next page](https://discourse.julialang.org/t/how-to-use-juliac-jl/123024.md?page=2)
