Skip to content

Commit b86dc72

Browse files
committed
update juliac instructions
1 parent dcd644c commit b86dc72

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,23 +234,25 @@ plot([res, res_fp], plotu=true, lab=["Float64" "" string(T) ""]); ylabel!("u + d
234234
The fixed-point controller behaves roughly the same in this case, but artifacts are clearly visible. If the number of bits used for the fractional part is decreased, the controller will start to misbehave.
235235

236236
## Compilation using JuliaC
237-
> [!IMPORTANT]
238-
> At the time of writing, this requires a nightly version of julia. Consider this example to be highly experimental for now!
239237

240238
This demonstration is part of the examples in the article:
241239
> [Bagge Carlson, et al. "C-code generation considered unnecessary: go directly to binary, do not pass C. Compilation of Julia code for deployment in model-based engineering." arXiv preprint arXiv:2502.01128 (2025).](https://arxiv.org/abs/2502.01128)
242240
243-
The file [`examples/juliac/juliac_pid.jl`](https://github.com/JuliaControl/DiscretePIDs.jl/blob/main/examples/juliac/juliac_pid.jl) contains a JuliaC-compatible interface that can be compiled into a C-callable shared library using JuliaC. To compile the file, run the following from the [`examples/juliac`](https://github.com/JuliaControl/DiscretePIDs.jl/tree/main/examples/juliac) folder:
241+
The file [`examples/juliac/juliac_pid.jl`](https://github.com/JuliaControl/DiscretePIDs.jl/blob/main/examples/juliac/juliac_pid.jl) contains a JuliaC-compatible interface that can be compiled into a C-callable shared library using JuliaC.
242+
First, install JuliaC by running `pkg> app add JuliaC` in the Julia REPL. Then, to compile the file, run the following from the [`examples/juliac`](https://github.com/JuliaControl/DiscretePIDs.jl/tree/main/examples/juliac) folder:
244243
```bash
245-
julia +nightly --project <PATH_TO_JULIA_REPO>/julia/contrib/juliac.jl --output-lib juliac_pid --experimental --trim=unsafe-warn --compile-ccallable juliac_pid.jl
244+
juliac --output-lib juliac_pid --experimental --trim=unsafe-warn --compile-ccallable --project=. juliac_pid.jl
246245
```
247-
where `<PATH_TO_JULIA_REPO>` should be replaced with the path to the Julia repository on your system. The command will generate a shared library `juliac_pid` that can be called from C. The file [`examples/juliac/juliac_pid.h`](https://github.com/JuliaControl/DiscretePIDs.jl/blob/main/examples/juliac/juliac_pid.h) contains the C-compatible interface to the shared library. The C program may be compiled with a command like
246+
The command will generate a shared library `juliac_pid.so` (or `.dylib`/`.dll`) that can be called from C.
247+
The file [`examples/juliac/juliac_pid.h`](https://github.com/JuliaControl/DiscretePIDs.jl/blob/main/examples/juliac/juliac_pid.h) contains the C-compatible interface to the shared library.
248+
The C program may be compiled with a command like
248249
```bash
249-
export LD_LIBRARY_PATH=<PATH_TO_JULIA_REPO>/julia/usr/lib:$LD_LIBRARY_PATH
250-
gcc -o pid_program test_juliac_pid.c -I <PATH_TO_JULIA_REPO>/julia/usr/include/julia -L<PATH_TO_JULIA_REPO>/julia/usr/lib -ljulia -ldl
250+
gcc -o pid_program test_juliac_pid.c -I $HOME/.julia/juliaup/julia-1.12.1+0.x64.linux.gnu/include/julia -L$HOME/.julia/juliaup/julia-1.12.1+0.x64.linux.gnu/lib -ljulia -ldl
251251
```
252+
(modify the Julia path to match your installation)
252253
and then run by
253254
```bash
255+
export LD_LIBRARY_PATH=$HOME/.julia/juliaup/julia-1.12.1+0.x64.linux.gnu/lib:$HOME/.julia/juliaup/julia-1.12.1+0.x64.linux.gnu/lib/julia:$LD_LIBRARY_PATH
254256
./pid_program
255257
```
256258
which should produce the output

examples/juliac/Project.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
[deps]
22
ControlSystemsBase = "aaaaaaaa-a6ca-5380-bf3e-84a91bcd477e"
33
DiscretePIDs = "c1363496-6848-4723-8758-079b737f6baf"
4-
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"

examples/juliac/juliac_pid.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ end
4444

4545
end
4646

47-
# compile using something like this, modified to suit your local paths
47+
# Compile using JuliaC (install with: pkg> app add JuliaC)
4848
# cd(@__DIR__)
49-
# run(`/home/fredrikb/repos/julia/julia --project --experimental /home/fredrikb/repos/julia/contrib/juliac.jl --output-lib juliac_pid --trim=unsafe-warn --experimental --compile-ccallable juliac_pid.jl`)
49+
# run(`juliac --output-lib juliac_pid --experimental --trim=unsafe-warn --compile-ccallable --project=. juliac_pid.jl`)
50+
# This generates juliac_pid.so (or .dylib/.dll) in the current directory
5051
# run(`ls -ltrh`)

examples/juliac/test_juliac_pid.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
#include "juliac_pid.h"
66

77
// Path to julia binary folder
8-
#define JULIA_PATH "/home/fredrikb/repos/julia/usr/bin/" // NOTE: modify this path
8+
#define JULIA_PATH "/home/fredrikb/.julia/juliaup/julia-1.12.1+0.x64.linux.gnu/bin/" // NOTE: modify this path to match your Julia installation
99

1010
// Path to juliac compiled shared object file
11-
#define LIB_PATH "/home/fredrikb/.julia/dev/DiscretePIDs/examples/juliac/juliac_pid.so" // NOTE: modify this path
11+
#define LIB_PATH "/home/fredrikb/.julia/dev/DiscretePIDs/examples/juliac/juliac_pid.so" // NOTE: modify this path if needed
1212

1313
int main() {
1414

@@ -58,6 +58,10 @@ int main() {
5858
}
5959

6060

61-
// Compile this C program using a command like the one above, modified to suit your paths
62-
// export LD_LIBRARY_PATH=/home/fredrikb/repos/julia/usr/lib:$LD_LIBRARY_PATH
63-
// gcc -o pid_program test_juliac_pid.c -I /home/fredrikb/repos/julia/usr/include/julia -L/home/fredrikb/repos/julia/usr/lib -ljulia -ldl
61+
// Compile this C program using a command like:
62+
// gcc -o pid_program test_juliac_pid.c -I $HOME/.julia/juliaup/julia-1.12.1+0.x64.linux.gnu/include/julia -L$HOME/.julia/juliaup/julia-1.12.1+0.x64.linux.gnu/lib -ljulia -ldl
63+
// (modify the Julia path to match your installation)
64+
//
65+
// Run with:
66+
// export LD_LIBRARY_PATH=$HOME/.julia/juliaup/julia-1.12.1+0.x64.linux.gnu/lib:$HOME/.julia/juliaup/julia-1.12.1+0.x64.linux.gnu/lib/julia:$LD_LIBRARY_PATH
67+
// ./pid_program

0 commit comments

Comments
 (0)