[C Interface (CAMLlocalN)] call__frame undeclared

,

Hi, I’m having an issue using a C foreign interface in my program. I’m trying to declare some variables using the CAMLlocalN schema, but I’m getting errors.

λ mysql-connect git:(master) ✗ dune exec main
      ocamlc lib/mySql_stubs.o (exit 2)
(cd _build/default/lib && /Users/cnevers/.opam/4.08.0/bin/ocamlc.opt -g -I /Users/cnevers/.opam/4.08.0/lib/base -I /Users/cnevers/.opam/4.08.0/lib/base/caml -I /Users/cnevers/.opam/4.08.0/lib/base/shadow_stdlib -I /Users/cnevers/.opam/4.08.0/lib/ppx_inline_test/config -I /Users/cnevers/.opam/4.08.0/lib/ppx_inline_test/runtime-lib -I /Users/cnevers/.opam/4.08.0/lib/sexplib0 -ccopt -I/usr/local/Cellar/mysql/8.0.16/include/mysql -ccopt -g -o mySql_stubs.o mySql_stubs.c)
mySql_stubs.c:65:3: error: use of undeclared identifier 'caml__frame'
  CAMLlocal2(cli_outer, cons_outer);
  ^
/Users/cnevers/.opam/4.08.0/lib/ocaml/caml/memory.h:421:3: note: expanded from macro 'CAMLlocal2'
  CAMLxparam2 (x, y)
  ^
/Users/cnevers/.opam/4.08.0/lib/ocaml/caml/memory.h:348:12: note: expanded from macro 'CAMLxparam2'
    (void) caml__frame, \
           ^
mySql_stubs.c:78:5: error: use of undeclared identifier 'caml__frame'
    CAMLlocal2(cli_inner, cons_inner);
    ^
/Users/cnevers/.opam/4.08.0/lib/ocaml/caml/memory.h:421:3: note: expanded from macro 'CAMLlocal2'
  CAMLxparam2 (x, y)
  ^
/Users/cnevers/.opam/4.08.0/lib/ocaml/caml/memory.h:348:12: note: expanded from macro 'CAMLxparam2'
    (void) caml__frame, \
           ^
mySql_stubs.c:101:3: error: use of undeclared identifier 'caml__frame'
  CAMLreturn (cli_outer);
  ^
/Users/cnevers/.opam/4.08.0/lib/ocaml/caml/memory.h:457:28: note: expanded from macro 'CAMLreturn'
#define CAMLreturn(result) CAMLreturnT(value, result)
                           ^
/Users/cnevers/.opam/4.08.0/lib/ocaml/caml/memory.h:453:3: note: expanded from macro 'CAMLreturnT'
  CAMLdrop; \
  ^
/Users/cnevers/.opam/4.08.0/lib/ocaml/caml/memory.h:444:37: note: expanded from macro 'CAMLdrop'
#define CAMLdrop caml_local_roots = caml__frame
                                    ^
3 errors generated.

I’m not sure where caml__frame is defined, but any help will be appreciated!

Just found this: https://github.com/savonet/ocaml-alsa/commit/8ec2a54c9714c85d1bb6a53ee1c529394c162b00.patch

seems to have answered my question!

yes, the CAMLlocal* macros expect a preceding CAMLparam* macro.
You most probably need a CAMLparam0() before your CAMLlocal.