# How to use custom sysimage if cannot set flags on Julia startup

**URL:** <https://discourse.julialang.org/t/how-to-use-custom-sysimage-if-cannot-set-flags-on-julia-startup/70482>\
**Category:** General Usage\
**Tags:** package-compiler, sysimage\
**Created:** [October 27, 2021, 2:06pm UTC](https://discourse.julialang.org/t/how-to-use-custom-sysimage-if-cannot-set-flags-on-julia-startup/70482 "2021-10-27T14:06:29Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bakaburg1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bakaburg1/32/30237_2.png) [@Bakaburg1](https://discourse.julialang.org/u/Bakaburg1)\
**Post date:** [October 27, 2021, 2:06pm UTC](https://discourse.julialang.org/t/how-to-use-custom-sysimage-if-cannot-set-flags-on-julia-startup/70482/1 "2021-10-27T14:06:29Z")

</div>

Hello,

I have a custom Julia package (only local) inside an R project. I’m interacting with the Julia package via [https://github.com/stefan-m-lenz/JuliaConnectoR](https://github.com/stefan-m-lenz/JuliaConnectoR).  
I’d like to precompile this package and its functions since their use is quite static and with similar inputs.

I understood how to create a custom sysimage using PackageCompiler.jl but I don’t know how to use it.  
Since JuliaConnectoR does not allow setting up flags on Julia startup is there another way to use the custom sysimage? like an environment variable or a Julia function to load the .so file after startup?

Thanks

---

<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:** [October 27, 2021, 2:46pm UTC](https://discourse.julialang.org/t/how-to-use-custom-sysimage-if-cannot-set-flags-on-julia-startup/70482/2 "2021-10-27T14:46:58Z")

</div>

You can maybe create a wrapper script and tell JuliaConnectoR to use that? E.g. something like

```julia
#!/bin/bash
exec /path/to/julia --sysimage=/path/to/sysimg.so "${@}"

```

---

<div class="post-metadata">

**Author:** ![Bakaburg1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bakaburg1/32/30237_2.png) [@Bakaburg1](https://discourse.julialang.org/u/Bakaburg1)\
**Post date:** [October 27, 2021, 3:34pm UTC](https://discourse.julialang.org/t/how-to-use-custom-sysimage-if-cannot-set-flags-on-julia-startup/70482/3 "2021-10-27T15:34:16Z")

</div>

> [@fredrikekre](#):
>
> `"${@}"`

Uhm, apparently not without modifying or overriding JuliaConnectoR code (I’m trying to do that now).

Btw, what’s “${@}”?

---

<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:** [October 27, 2021, 4:34pm UTC](https://discourse.julialang.org/t/how-to-use-custom-sysimage-if-cannot-set-flags-on-julia-startup/70482/4 "2021-10-27T16:34:11Z")

</div>

[The docs say](https://github.com/stefan-m-lenz/JuliaConnectoR#installation):

> The package requires that Julia (version ≥ 1.0) is installed and that the Julia executable is in the system search PATH or that the JULIA\_BINDIR environment variable is set to the bin directory of the Julia installation.

so I guess if call my script `julia`, make it executable and put it in a folder in `PATH` it should pick it up.

> [@Bakaburg1](#):
>
> Btw, what’s “${@}”?

It is all the parameters passed to this script, see e.g. [this answer on StackOverflow](https://stackoverflow.com/questions/9994295/what-does-mean-in-a-shell-script).

---

<div class="post-metadata">

**Author:** ![Bakaburg1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bakaburg1/32/30237_2.png) [@Bakaburg1](https://discourse.julialang.org/u/Bakaburg1)\
**Post date:** [October 27, 2021, 4:43pm UTC](https://discourse.julialang.org/t/how-to-use-custom-sysimage-if-cannot-set-flags-on-julia-startup/70482/5 "2021-10-27T16:43:36Z")

</div>

After speaking with the package author (a friend of mine), while he implements the possibility to pass flags at startup he suggested me to use aliases.  
I’m now trying to understand how to since it seems the aliases disappear between command-line sessions.  
e.g. in R:

```julia
> system("alias julia2='julia'")
> system("julia2")
sh: julia2: command not found

```

---

<div class="post-metadata">

**Author:** ![Bakaburg1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bakaburg1/32/30237_2.png) [@Bakaburg1](https://discourse.julialang.org/u/Bakaburg1)\
**Post date:** [October 27, 2021, 4:45pm UTC](https://discourse.julialang.org/t/how-to-use-custom-sysimage-if-cannot-set-flags-on-julia-startup/70482/6 "2021-10-27T16:45:01Z")

</div>

Wouldn’t that mean that every time I use Julia from the command-line it would use the wrapper script?

---

<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:** [October 27, 2021, 4:53pm UTC](https://discourse.julialang.org/t/how-to-use-custom-sysimage-if-cannot-set-flags-on-julia-startup/70482/7 "2021-10-27T16:53:52Z")

</div>

Yea I guess. You can use a directory dependent `PATH` variable with [`direnv`](https://direnv.net/). I wrote about it in [this post about `direnv` and Julia](https://fredrikekre.se/posts/direnv-with-julia/).

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [October 28, 2021, 9:36am UTC](https://discourse.julialang.org/t/how-to-use-custom-sysimage-if-cannot-set-flags-on-julia-startup/70482/8 "2021-10-28T09:36:26Z")

</div>

> [@Bakaburg1](#):
>
> Wouldn’t that mean that every time I use Julia from the command-line it would use the wrapper script?

I don’t know R, but can’t you set the `PATH` envvar from your R process before it tries to spawn the Julia process?

---

<div class="post-metadata">

**Author:** ![Bakaburg1](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bakaburg1/32/30237_2.png) [@Bakaburg1](https://discourse.julialang.org/u/Bakaburg1)\
**Post date:** [October 28, 2021, 11:46am UTC](https://discourse.julialang.org/t/how-to-use-custom-sysimage-if-cannot-set-flags-on-julia-startup/70482/9 "2021-10-28T11:46:49Z")

</div>

Eventually I decided to fork and edit the JuliaConnector package directly to allow arguments.
