# New on Forem: “StaticCompiler - Generating small binaries"

**URL:** https://discourse.julialang.org/t/new-on-forem-staticcompiler-generating-small-binaries/130464
**Category:** General Usage
**Tags:** staticcompiler
**Created:** [July 4, 2025, 7:58am UTC](https://discourse.julialang.org/t/new-on-forem-staticcompiler-generating-small-binaries/130464 "2025-07-04T07:58:50Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)
#### Post date: [July 4, 2025, 7:58am UTC](https://discourse.julialang.org/t/new-on-forem-staticcompiler-generating-small-binaries/130464/1 "2025-07-04T07:58:50Z")

</div>

@Thomas008 shares some valuable experiences of using StaticCompiler to generate binaries out from Julia code:

> **[StaticCompiler - Generating small binaries](https://forem.julialang.org/thomas008/staticcompiler-generating-small-binaries-mp0)**
>
> Static compilation with help of StaticCompiler Here I'd like to share some experiences of using...

Thanks for sharing this!

---

<div class="post-metadata">

### Author: ![karei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karei/32/214809_2.png) [@karei](https://discourse.julialang.org/u/karei)
#### Post date: [July 4, 2025, 8:05am UTC](https://discourse.julialang.org/t/new-on-forem-staticcompiler-generating-small-binaries/130464/2 "2025-07-04T08:05:22Z")

</div>

I benefited a lot from Thomas008’s tutorial on StaticCompiler. I am trying to make a dll of my own, I need to work with array data, but I encountered an error when I tried to compile the following code. I want to know if there is a way to fix it.

```julia
function calc(a, b)
    a .*= b
    return 0
end
path = compile_shlib(calc, (Vector{Int}, Vector{Int}), "./")

```

gives

```julia
┌ Warning: Found pointer references to julia data
│ llvm instruction = %14 = call nonnull {}* inttoptr (i64 140728530324048 to {}* ({}*)*)({}* nonnull %1)
│ name = :ijl_array_copy
│ file = Symbol("C:/workdir/src\\array.c")
│ line = 1176
│ fromC = true
│ inlined = false
└ @ StaticCompiler

```

---

<div class="post-metadata">

### Author: ![Thomas008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thomas008/32/204169_2.png) [@Thomas008](https://discourse.julialang.org/u/Thomas008)
#### Post date: [November 27, 2025, 5:41pm UTC](https://discourse.julialang.org/t/new-on-forem-staticcompiler-generating-small-binaries/130464/3 "2025-11-27T17:41:07Z")

</div>

> [@karei](#):
>
> ```julia-auto
> function calc(a, b)
> a .*= b
> return 0
> end
> path = compile_shlib(calc, (Vector{Int}, Vector{Int}), "./")
> 
> ```

The problem is that the operator .\* needs GC allocations. So it is not compilable for StaticCompiler.

---

<div class="post-metadata">

### Author: ![ForceBru](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/forcebru/32/21389_2.png) [@ForceBru](https://discourse.julialang.org/u/ForceBru)
#### Post date: [November 27, 2025, 6:29pm UTC](https://discourse.julialang.org/t/new-on-forem-staticcompiler-generating-small-binaries/130464/4 "2025-11-27T18:29:35Z")

</div>

> [@Thomas008](#):
>
> operator .\* needs GC allocations

Wait, I thought `x .*= y` and other `.=`-like operators modify `x` in-place and therefore don’t allocate?

---

<div class="post-metadata">

### Author: ![karei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karei/32/214809_2.png) [@karei](https://discourse.julialang.org/u/karei)
#### Post date: [November 28, 2025, 12:29am UTC](https://discourse.julialang.org/t/new-on-forem-staticcompiler-generating-small-binaries/130464/5 "2025-11-28T00:29:19Z")

</div>

I also thought it modified x in-place. So do I need to write a for loop?

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [November 28, 2025, 8:41am UTC](https://discourse.julialang.org/t/new-on-forem-staticcompiler-generating-small-binaries/130464/6 "2025-11-28T08:41:45Z")

</div>

> [@Thomas008](#):
>
> The problem is that the operator .\* needs GC allocations. So it is not compilable for StaticCompiler.

This is not correct:

```julia-auto
julia> using BenchmarkTools

julia> x, y = rand(0:9, 5), rand(0:9, 5)
([9, 9, 7, 7, 8], [1, 6, 7, 9, 4])

julia> @ballocated calc(x, y)
0

```

---

<div class="post-metadata">

### Author: ![Thomas008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thomas008/32/204169_2.png) [@Thomas008](https://discourse.julialang.org/u/Thomas008)
#### Post date: [November 28, 2025, 6:14pm UTC](https://discourse.julialang.org/t/new-on-forem-staticcompiler-generating-small-binaries/130464/7 "2025-11-28T18:14:02Z")

</div>

Oh yes, you are right.  
(I gave constants to calc, i.e. calc([1,2],[3,4]), which causes allocations. But using variables, which is the actual use, causes no allocations.)

---

<div class="post-metadata">

### Author: ![Thomas008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/thomas008/32/204169_2.png) [@Thomas008](https://discourse.julialang.org/u/Thomas008)
#### Post date: [November 28, 2025, 6:21pm UTC](https://discourse.julialang.org/t/new-on-forem-staticcompiler-generating-small-binaries/130464/8 "2025-11-28T18:21:01Z")

</div>

I can repeat this error on my machine with StaticCompiler, although there are no allocations. This would be something to report to the issues of StaticCompiler:  
[https://github.com/tshort/StaticCompiler.jl/issues](https://github.com/tshort/StaticCompiler.jl/issues)

---

<div class="post-metadata">

### Author: ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)
#### Post date: [November 29, 2025, 3:42am UTC](https://discourse.julialang.org/t/new-on-forem-staticcompiler-generating-small-binaries/130464/9 "2025-11-29T03:42:34Z")

</div>

> [@karei](#):
>
> `Warning: Found pointer references to julia data`

I don’t think it’s totally clear what we’re allowed to do, but it seems clear we can’t work on `Vector{Int}`:

> To enable code to be statically compiled, consider the following:
> 
> - Avoid Julia’s internal allocations. That means don’t bake in use of Arrays or Strings or Dicts. Types from StaticTools can help, like StaticStrings and MallocArrays.  
> …
> - Arguments and returned values from `compile_shlib` must be native objects such as `Int`, `Float64`, or `Ptr`. They cannot be things like `Tuple{Int, Int}` because that is not natively sized. Such objects need to be passed by reference instead of by value.

If you want to precompile a function that takes Julia `Vector{Int}` inputs, stay in base Julia with package precompilation. Other languages won’t even be able to provide a `Vector{Int}`.

---

<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: [November 29, 2025, 8:53am UTC](https://discourse.julialang.org/t/new-on-forem-staticcompiler-generating-small-binaries/130464/10 "2025-11-29T08:53:37Z")

</div>

Yes, `Vector{Int}` is off the table. Either use `MallocArrays` or define your own vector type, like I did in [Successful Static Compilation of Julia Code for use in Production](https://discourse.julialang.org/t/successful-static-compilation-of-julia-code-for-use-in-production/79318#vectors-11). That also contains some discussion of how to call it from Python.
