Skip to content

Instantly share code, notes, and snippets.

@saschatimme
Last active June 3, 2021 03:19
Show Gist options
  • Save saschatimme/46d985aeaf3fbc47a0296f8874d7c936 to your computer and use it in GitHub Desktop.
Save saschatimme/46d985aeaf3fbc47a0296f8874d7c936 to your computer and use it in GitHub Desktop.
make.txt
#include <stdio.h>
#include <caml/callback.h>
extern int fib(int n);
extern char * format_result(int n);
int main(int argc, char ** argv)
{
int result;
/* Initialize OCaml code */
caml_startup(argv);
/* Do some computation */
result = fib(10);
printf("fib(10) = %s\n", format_result(result));
return 0;
}
# This works
# mod.ml is some ocaml code
# modwrap.c is a wrapper which calls the registered callbacks
# libasmrun is a runtime library
simplewrapper:
ocamlopt -output-obj -o modcaml.o mod.ml
ocamlc -c modwrap.c ;\
cp `ocamlc -where`/libasmrun.a libmod.a && chmod +w libmod.a ;\
ar r libmod.a modcaml.o modwrap.o
main:
cc -o prog -I `ocamlc -where` main.c libmod.a
# Now has the compiler another mode
# -output-complete-obj
# That includes the runtime library directly into modcaml.o
simplewrapper2:
ocamlopt -output-complete-obj -o modcaml.o mod.ml
ocamlc -c modwrap.c ;\
ar rcs libmod.a modcaml.o modwrap.o
main2:
cc -o prog -I `ocamlc -where` main.c libmod.a
# BUT now can I not compile the main file anymore.
# Error:
# Undefined symbols for architecture x86_64:
# "_caml_code_area_end", referenced from:
# _segv_handler in libmod.a(modcaml.o)
# "_caml_code_area_start", referenced from:
# _segv_handler in libmod.a(modcaml.o)
# "_caml_startup", referenced from:
# _main in main-bd2140.o
# (maybe you meant: _caml_startup__data_end, _caml_startup__data_begin , _caml_startup__frametable , _caml_startup__code_end , _caml_startup__code_begin )
# "_caml_system__code_end", referenced from:
# _segv_handler in libmod.a(modcaml.o)
# ld: symbol(s) not found for architect 86_64
@mimoo
Copy link

mimoo commented Jun 3, 2021

did you fix this? I'm getting the same error :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment