<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On 2009-01-19, at 13:50, Nick Lewycky wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>I have an issue with the OCaml build system and the ExecutionEngine.<br><br>PR2128 has a patch to change the Interpreter to use libffi. This breaks test/Bindings/Ocaml/executionengine.ml because OCaml doesn't try to link with libffi, even though llvm-config knows that we should:<br><br> $ Debug/bin/llvm-config --ldflags interpreter<br> -L/home/nicholas/llvm-commit/Debug/lib -lpthread -lffi -ldl -lm -lelf<br><br>If I run 'ocamlc' by hand and pass it '-cclib -lffi', the test succeeds, so this is the only remaining problem. Is anyone familiar with how Ocaml knows what libraries to link against? We can't just pass `llvm-config --ldflags interpreter` to ocamlc because it doesn't support the -L argument.<br><br>Does anyone have any ideas how this ought to work?<br></div></blockquote></div><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><br></div><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; ">The linker flags for each .cma (ocaml library) are baked in by ocaml. Here's the relevant section from Makefile.ocaml:</div><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><br></div></span></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><span class="Apple-style-span" style="font-family: 'Courier New'; "># Info from llvm-config and similar</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">ifdef UsedComponents</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">UsedLibs = $(shell $(LLVM_CONFIG) --libs $(UsedComponents))</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">UsedLibNames = $(shell $(LLVM_CONFIG) --libnames $(UsedComponents))</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">endif</span><br><br><span class="Apple-style-span" style="font-family: 'Courier New'; "># Tools</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">OCAMLCFLAGS += -I $(OcamlDir) -I $(ObjDir)</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">ifneq ($(ObjectsO),)</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">OCAMLAFLAGS += $(patsubst %,-cclib %, \</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; "> $(filter-out -L$(LibDir),-l$(LIBRARYNAME) \</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; "> $(shell $(LLVM_CONFIG) --ldflags)) \</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; "> $(UsedLibs))</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">else</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">OCAMLAFLAGS += $(patsubst %,-cclib %, \</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; "> $(filter-out -L$(LibDir),$(shell $(LLVM_CONFIG) --ldflags)) \</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; "> $(UsedLibs))</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">endif</span></blockquote><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><div><br></div><div>This transforms "x y z" from llvm-config into "-cclib x -cclib y -cclib z", which instructs ocaml to pass "x y z" down to the linker when creating an executable. The UsedComponents variable originates in this case from bindings/ocaml/executionengine/Makefile:</div><div><br></div></div></span></div><blockquote class="webkit-indent-blockquote" style="margin: 0 0 0 40px; border: none; padding: 0px;"><span class="Apple-style-span" style="font-family: 'Courier New'; ">LEVEL := ../../..</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">LIBRARYNAME := llvm_executionengine</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">DONT_BUILD_RELINKED := 1</span><br><span class="Apple-style-span" style="font-family: 'Courier New'; "><b><font class="Apple-style-span" color="#0000FF">UsedComponents := executionengine jit interpreter native</font></b></span><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">UsedOcamlInterfaces := llvm llvm_target</span><br><br><span class="Apple-style-span" style="font-family: 'Courier New'; ">include ../Makefile.ocaml</span></blockquote><div apple-content-edited="true"><span class="Apple-style-span" style="border-collapse: separate; border-spacing: 0px 0px; color: rgb(0, 0, 0); font-family: Trebuchet MS; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; text-align: auto; -khtml-text-decorations-in-effect: none; text-indent: 0px; -apple-text-size-adjust: auto; text-transform: none; orphans: 2; white-space: normal; widows: 2; word-spacing: 0px; "><div style="word-wrap: break-word; -khtml-nbsp-mode: space; -khtml-line-break: after-white-space; "><div><div><br></div><div>I don't see anything obviously wrong here; it seems that <font class="Apple-style-span" face="'Courier New'">llvm-config -ldflags executionengine jit interpreter native</font> should be invoked, which should give you the <font class="Apple-style-span" face="'Courier New'">-cclib -lffi</font> you seek. <font class="Apple-style-span" face="'Courier New'">make VERBOSE=1</font> and/or <font class="Apple-style-span" face="'Courier New'">TOO_VERBOSE=1</font> should show you the full ocaml command lines; maybe that'll show where -lffi is getting dropped on the floor.</div></div><div><br></div><div>— Gordon</div></div></span> </div><br></body></html>