xavierleroy / camlidl

Stub code generator for OCaml/C interface
Other
34 stars 8 forks source link

linking against libcamlidl is complicated #8

Closed ygrek closed 5 years ago

ygrek commented 5 years ago

Currently one needs to pass -lcamlidl manually when including camlidl generated code into project, which can be quite non-obvious to achieve with modern build systems. It would be much simpler if -package camlidl did that automatically. The patch below achieves the effect, and I believe ocaml compiler drops com.cmxa from final binary when it is not referenced so there is no extra cost. This might cause problems on windows where it can be even more cumbersome to link against distributed C libraries, so the other option would be to have separate ocamlfind package with empty cma only for the purpose of embedding -cclib.

diff --git a/lib/Makefile b/lib/Makefile
index c544b5e..aa0c47d 100644
--- a/lib/Makefile
+++ b/lib/Makefile
@@ -23,10 +23,10 @@ INTERFACES=$(BYTEOBJS:.cmo=.cmi)
 all: $(BYTELIB) $(NATIVELIB)

 $(BYTELIB): $(BYTEOBJS)
-       $(OCAMLC) -a -o $(BYTELIB) $(BYTEOBJS)
+       $(OCAMLC) -a -o $(BYTELIB) -cclib -lcamlidl $(BYTEOBJS)

 $(NATIVELIB): $(NATIVEOBJS)
-       $(OCAMLOPT) -a -o $(NATIVELIB) $(NATIVEOBJS)
+       $(OCAMLOPT) -a -o $(NATIVELIB) -cclib -lcamlidl $(NATIVEOBJS)

 install:
        cp $(INTERFACES) $(BYTELIB) $(NATIVELIB) $(NATIVELIB:.cmxa=.$(LIBEXT)) $(OCAMLLIB)
ygrek commented 5 years ago

ping

xavierleroy commented 5 years ago

Sorry for leaving this issue open for so long. I agree with the proposed solution. For bytecode we can have -dllib -lcamlidl in addition, so that the DLL can be automatically used too. It's in commit d8f7a3f . I do hope there will be no issues with double linking of -lcamlidl.