llvm 2.2 install and ocaml bindings

I've run into a problem with the ocaml bindings and the jit. It builds
fine without the jit, but when I try to include it it tries to use the
c object files from the build location, instead of the install
location:

llvm-config --libdir --libfiles engine

/opt/local/lib
/opt/local/lib/LLVMX86.o /opt/local/lib/libLLVMSelectionDAG.a
/opt/local/lib/libLLVMCodeGen.a /opt/local/lib/libLLVMScalarOpts.a
/opt/local/lib/libLLVMTransformUtils.a /opt/local/lib/libLLVMipa.a
/opt/local/lib/libLLVMAnalysis.a /opt/local/lib/LLVMExecutionEngine.o
/opt/local/lib/LLVMJIT.o /opt/local/lib/libLLVMTarget.a
/opt/local/lib/libLLVMCore.a /opt/local/lib/libLLVMSupport.a
/opt/local/lib/libLLVMSystem.a

ocamlc -g -cc g++ -I `llvm-config --libdir --libfiles engine` -o toy llvm.cma llvm_analysis.cma llvm_executionengine.cma lexer.cmo parser.cmo codegen.cmo main.ml

i686-apple-darwin8-g++-4.0.1:
/opt/local/var/macports/build/_Users_Shared_erickt_Projects_macports_dports.git_lang_llvm/work/build/Release/lib/LLVMX86.o:
No such file or directory
i686-apple-darwin8-g++-4.0.1:
/opt/local/var/macports/build/_Users_Shared_erickt_Projects_macports_dports.git_lang_llvm/work/build/Release/lib/LLVMInterpreter.o:
No such file or directory
i686-apple-darwin8-g++-4.0.1:
/opt/local/var/macports/build/_Users_Shared_erickt_Projects_macports_dports.git_lang_llvm/work/build/Release/lib/LLVMExecutionEngine.o:
No such file or directory
i686-apple-darwin8-g++-4.0.1:
/opt/local/var/macports/build/_Users_Shared_erickt_Projects_macports_dports.git_lang_llvm/work/build/Release/lib/LLVMJIT.o:
No such file or directory
Error while building custom runtime system
make: *** [all] Error 2

Since it's just a temporary build, it obviously doesn't exist any more
:slight_smile: Does anyone know how to fix this?

-e

Erick,

I see the problem. The llvm-config linker options are baked into the ocaml library, which is good. But for the execution engine, that link line includes the full paths to some .o files. Those paths come from llvm-config, and they vary before and after installation. (Before install, they point into the source tree as you’re seeing.) You could theoretically get working .cma’s by somehow building the bindings against an installed llvm-config.

LLVMers, what’s the advantage to building .o files instead of .a’s for these libs?

LLVMARM.o
LLVMAlpha.o
LLVMCBackend.o
LLVMCellSPU.o
LLVMExecutionEngine.o
LLVMIA64.o
LLVMInterpreter.o
LLVMJIT.o
LLVMMSIL.o
LLVMMips.o
LLVMPowerPC.o
LLVMSparc.o
LLVMX86.o

This wouldn’t be a problem if these components used .a’s instead, since ld’s search paths are set up correctly.

The options I see are:

  • Use archive libraries instead of objects for the above.
  • Link the above .o files into .a’s just for the ocaml bindings. Kind of strange, but could be perfectly workable; ocaml already builds .a files for the bindings, a few more wouldn’t hurt… much.
  • Recompile the bindings at install time just to change the baked-in link line.
  • Don’t bake the link line into the bindings at all. Make ocaml users add the llvm-config invocation to their link lines by hand.
  • Fool ocamlc into invoking llvm-config from its link line? I do not believe this is possible—I doubt it launches a shell to run the linker.

Thanks,
Gordon

P.S. — You shouldn’t need to use llvm-config in conjunction with the ocaml bindings. Unless this gets resolved by the fourth option.

Thanks Gordon. I have to use "llvm-config --libdir" since I have llvm
installed in a nonstandard location. The "--libfiles" I was just
messing around with to see if ocaml would find where the files are
installed, but that didn't work.