Skip to content

Commit

Permalink
Merge pull request #4 from AtelierArith/hello-example-without-cmake
Browse files Browse the repository at this point in the history
Hello example without cmake
  • Loading branch information
terasakisatoshi authored May 31, 2024
2 parents 1ed6aeb + cfc0f3f commit 66d5d96
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ jobs:
- uses: julia-actions/cache@v1
- name: Run hello_gcc
run: cd hello_gcc && bash run.sh
- name: Run hello_gcc_cmake
run: cd hello_gcc && bash run.sh
- name: Run hello_cxx
run: cd hello_cxx && bash run.sh
- name: Run complicatedexamples
Expand Down
1 change: 1 addition & 0 deletions hello_gcc/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
main
2 changes: 2 additions & 0 deletions hello_gcc/main.c
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// https://docs.julialang.org/en/v1/manual/embedding/

#include <julia.h>
JULIA_DEFINE_FAST_TLS // only define this once, in an executable (not in a shared library) if you want fast code.

Expand Down
6 changes: 3 additions & 3 deletions hello_gcc/run.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Get Julia installation paths
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release
cmake --build ./build --config Release -j `nproc`
./build/hello
JULIA_DIR=`julia -e 'print(dirname(Sys.BINDIR))'`
gcc -o ./main -fPIC -I$JULIA_DIR/include/julia -L$JULIA_DIR/lib -Wl,-rpath,$JULIA_DIR/lib main.c -ljulia
./main
File renamed without changes.
9 changes: 9 additions & 0 deletions hello_gcc_cmake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Hello World with C

- Install Julia in advance
- Just run the following command:

```sh
$ bash run.sh
1.4142135623730951
```
19 changes: 19 additions & 0 deletions hello_gcc_cmake/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include <julia.h>
JULIA_DEFINE_FAST_TLS // only define this once, in an executable (not in a shared library) if you want fast code.

int main(int argc, char *argv[])
{
/* required: setup the Julia context */
jl_init();

/* run Julia commands */
jl_eval_string("print(sqrt(2.0))");

/* strongly recommended: notify Julia that the
program is about to terminate. this allows
Julia time to cleanup pending write requests
and run all finalizers
*/
jl_atexit_hook(0);
return 0;
}
4 changes: 4 additions & 0 deletions hello_gcc_cmake/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Get Julia installation paths
cmake -S . -B ./build -DCMAKE_BUILD_TYPE=Release
cmake --build ./build --config Release -j `nproc`
./build/hello

0 comments on commit 66d5d96

Please sign in to comment.