I had a problem with the order of adding libraries to the linker. The previously built ocamlbuild libraries are linked in the list of libraries included in the flag rule. And I see no way to define this type of dependency in myocamlbuild.ml .
In particular, the problem is related to the previously built library ( gzcaml ), which requires the library itself ( z ). Due to the added rigor in new versions of gcc, the -lz argument should appear after libgzcaml.a .
I include all of these libraries,
flag ["ocaml"; "link"] (S (process "-cclib" clibs))
where process creates a list interleaving the library and A"-cclib" , respectively.
In addition, additional libraries are added (from the verbose output, -lm and -ldl ), but I have no idea how I can change / add them? (this will instantly solve my problem).
My myocamlbuild.ml quite long, I would include it here. I tried moving the code above to the bottom of After_rules , at the top. And it changes order, but never after the built-in libraries (c and otherwise) created previously by ocamlbuild.
EDIT Below are the code snippets that I used in the script and ocamlbuild settings to solve the problem above. Hurrah!
in configure.ac
oCFLAGS="$CFLAGS" CFLAGS="$FLAGS -Wl,--no-as-needed" AC_MSG_CHECKING([whether we need to add --no-as-needed linking option]) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[ int main(){ return 0; } ]])], [AC_MSG_RESULT([yes]); CC_NOASNEEDED="true"], [AC_MSG_RESULT([no]); CC_NOASNEEDED="false"]) CFLAGS=$oCFLAGS
in myocamlbuild.ml.in
if @ CC_NOASNEEDED@ then flag ["ocaml"; "link"] (S [A"-cclib";A"-Wl,--no-as-needed"]);