[llvm] [CMake][OCaml] Make OCaml bindings suitable for out-of-tree install (PR #123478)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 24 21:09:39 PST 2025
alan-j-hu wrote:
Thank you for the review. The CMake code on the main branch is
```cmake
if( NOT BUILD_SHARED_LIBS )
list(APPEND ocaml_flags "-custom")
endif()
```
I did some investigation and figured out that if you leave out the `-custom` flag, when you run the test suite, you will hit errors that look like
```
: CommandLine Error: Option 'experimental-debuginfo-iterators' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options
```
and the tests will fail.
This seems to be an issue with CommandLine, talked about at https://discourse.llvm.org/t/rfc-commandline-allow-loading-1-library-linking-to-the-same-libllvm-version/67542. If `BUILD_SHARED_LIBS=ON`, then this error will occur. Passing the `-custom` flag when building the OCaml bindings forces static linking, avoiding this issue.
However, it seems that when building out-of-tree and installing the bindings as an OCaml package, the `-custom` flag causes bytecode executables not to work. I get errors that look like:
```
/usr/bin/ld: cannot find -lllvm_analysis: No such file or directory
/usr/bin/ld: cannot find -lllvm_executionengine: No such file or directory
/usr/bin/ld: cannot find -lctypes_stubs: No such file or directory
/usr/bin/ld: cannot find -lintegers_stubs: No such file or directory
/usr/bin/ld: cannot find -lllvm_target: No such file or directory
/usr/bin/ld: cannot find -lllvm: No such file or directory
collect2: error: ld returned 1 exit status
```
(I tried testing this with LLVM 14, which is the last version published on OPAM to build with CMake, but the bytecode executable failed to build for a different reason that has since been fixed: https://discuss.ocaml.org/t/llvm-symbol-not-found-for-bytecode-compilation/8728.)
So, it seems that when building in-tree, `-custom` is necessary for building bytecode executables, but when building out-of-tree and installing, `-custom` causes the bytecode executable to fail. (The `-custom` flag only affects bytecode executables generated by `ocamlc`, not native executables generated by `ocamlopt`.)
https://github.com/llvm/llvm-project/pull/123478
More information about the llvm-commits
mailing list