Skip to content

Commit

Permalink
Use C
Browse files Browse the repository at this point in the history
  • Loading branch information
terasakisatoshi committed May 26, 2024
1 parent 81fd27a commit 0ee1437
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
9 changes: 9 additions & 0 deletions hello_gcc/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/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;
}
3 changes: 3 additions & 0 deletions hello_gcc/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
JULIA_DIR=`julia -e 'print(dirname(Sys.BINDIR))'`
gcc -fPIC -I$JULIA_DIR/include/julia -L$JULIA_DIR/lib -Wl,-rpath,$JULIA_DIR/lib main.c -ljulia
./a.out

0 comments on commit 0ee1437

Please sign in to comment.