Order linked libraries in ocamlbuild

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"]); 
+6
source share
1 answer

This is not an answer, but a workaround - disable this behavior of the new linker with -cclib -Wl,--no-as-needed .

I think this should be reported as a mistake for a mantis. In particular, ocamlbuild must ensure that the parameters from flag are inserted on the command line in the same order as they appear in the source (this is happening in afair now), and ocamlopt must preserve the order of -cclib and -ccopt arguments for other entries in the command line (this is not the case now).

+4
source

Source: https://habr.com/ru/post/902587/


All Articles