Correct usage of llvm bindings

I recently installed the llvm package (version 19-static) via opam on an iMac M4. All seemed to go OK. When I came to build a small dune project to play with llvm I got a warning:
ld: warning: ignoring duplicate libraries: '-lLLVMAArch64AsmParser', '-lLLVMAArch64CodeGen', '-lLLVMAArch64Desc', '-lLLVMAArch64Disassembler', ... '-lLLVMXCoreInfo', '-lc++', '-lm', '-lz', '-lzstd'

The project executed as I expected but I’m wondering how to get rid of the warning?

Here’s the dune file for the project:

(executable
 (name Targets)
 (libraries
    base
    stdio
    llvm
    llvm.target
    llvm.all_backends
    llvm.executionengine
 )
)

Any suggestions gratefully received.

I once made a working example for llvm-14 and llvm-16 at arbipher/llvm-ocaml-tutorial, but I haven’t touched it for a while.

Can you share your full code, so that I can look at it recently?

Thanks for your reply.

My project is a single file so I have created a GitHub gist of it and its dune file.
(Table of llvm targets · GitHub)

The program prints the default target triple and then a table of all target architectures available in the installed llvm.

Try linking only the specific libs and not the one only called “llvm”. At least that’s what I do in my project (schmu/lib/dune at main · tjammer/schmu · GitHub).

Thanks for the suggestion. I tried it but still got a warning:

ld: warning: ignoring duplicate libraries: '-lLLVM-19', '-lc++', '-lm', '-lz', '-lzstd'

I currently have llvm.19-shared installed rather than llvm.19-static (as in my first message) which I believe accounts for the fewer number of duplicate libraries reported.

I get the same warning whether or not I omit “llvm”.

I’ve looked at dune’s log file and at some tracing from the ocamlopt.opt command dune invokes to link my executable. From the latter I can see that for each library from the llvm bindings package that my executable references ocamlopt.opt emits a -l argument for the appropriate library plus five others: -lLLVM-19 -lc++ -lm -lz -lzstd. The macOS build tool (clang) generates the warning I see about these duplicate libraries.

I’ll report this minor inconvenience to the maintainer of the llvm bindings if I can but I’m going to stop worrying about it now.

1 Like