From: Matthieu Dubuget <matthieu.dubuget@gmail.com>
To: Caml-list <caml-list@inria.fr>
Subject: [Caml-list] Flexlink/MinGW/Ctypes linking problem
Date: Wed, 19 Jul 2017 08:55:21 +0200 [thread overview]
Message-ID: <1975ba84-1540-ab23-40f0-307420e905a9@gmail.com> (raw)
Hello,
I'm currently trying to compile and link an OCaml program which calls
C++ libraries (Open Cascade). It works fine on linux, but not on
windows. I'm not sure why, and would need some advice: when I run my
program — either a bytecode version or the native one — an exception
is raised: exception Dl.DL_error("dlsym: no such symbol").
This OCaml program is calling C functions, using Ctypes.Foreign.
Those C functions are defined in a small CPP stub file with only an
extern "C" section. Those C functions are making use of the
OpenCascade C++ libraries.
Here are my (failing) attempts on windows:
I cross-compiled the C++ libraries with Debian 9 mingw-w64 toolchain,
and I checked that they are working with a small
x86_64-w64-mingw32-gcc.exe compiled C test program on windows.
I produced a DLL with something like:
GCC = x86_64-w64-mingw32-gcc.exe
OCCT_LIBS = TKSTEP TKMesh TKSTL TKSTEPAttr TKSTEP209 TKSTEPBase TKXSBase TKShHealing TKTopAlgo TKGeomAlgo TKBRep TKGeomBase TKG3d TKG2d TKMath TKernel stdc++
occ_stubs.o: occ_stubs.cpp occ_stubs.h
$(GCC) -c -Wall -std=gnu++11 -march=x86-64 -mtune=generic -O2 -mms-bitfields -Wno-unused -Wall -I$(OCCT_INC_DIR) $< -o $@
libocc_occt_stubs.dll: occ_stubs.o
$(GCC) -shared -std=gnu99 -march=x86-64 -mtune=generic -O2 -mms-bitfields -Wno-unused -Wall -o $@ $< -L$(OCCT_BIN_DIR) $(patsubst %,-l%,$(OCCT_L_LIBS))
I checked libocc_occt_stubs.dll with a small test program compiled with:
occt_test3.exe : occt_test3.c
$(CC) -o $@ $< -L$(LIB_DIR) -locc_occt_stubs -L$(OCCT_BIN_DIR) $(patsubst %,-l%,$(OCCT_LIBS))
CMXA and CMA are generated like this:
ocOcct.cma : refHandle.cmo occt.cmo libocc_occt_stubs.dll
ocamlfind c -a -o $@ -package $(OCAMLPACKAGES) refHandle.cmo occt.cmo -cclib -locc_occt_stubs5 -dllib libocc_occt_stubs.dll
ocOcct.cmxa : refHandle.cmx occt.cmx libocc_occt_stubs.dll
ocamlfind opt -a -o $@ -package $(OCAMLPACKAGES) refHandle.cmx occt.cmx -ccopt "-link -Wl,-rpa th=$(STUBLIBS_DIR)" -ccopt -L$(STUBLIBS_DIR) -cclib -locc_occt_stubs
and installed with ocamlfind.
Finally, the test program is linked again the .cmxa or .cma library with:
ocamlfind ocamlc -linkpkg -package gg -package yojson -package atdgen -package ococct -package unix -I lib -I pgm lib/aperture.cmo lib/calculette_t.cmo lib/calculette_j.cmo lib/coords.cmo lib/utils.cmo lib/product.cmo lib/essai3d.cmo lib/minim.cmo lib/probe.cmo lib/shot.cmo lib/speeds.cmo lib/conf.cmo lib/occtStub.cmo lib/calcback.cmo pgm/calculette.cmo -o pgm/calculette.byte
But when I'm running it, I get:
$ ./calculette.byte
Fatal error: exception Dl.DL_error("dlsym: no such symbol")
No master relocation table
And with the native version:
$ ./calculette.native
Fatal error: exception Dl.DL_error("dlsym: no such symbol")
What am I doing wrong?
Thanks
--
Matthieu Dubuget
next reply other threads:[~2017-07-19 6:55 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-19 6:55 Matthieu Dubuget [this message]
2017-07-19 8:29 ` Nicolás Ojeda Bär
2017-07-21 9:13 ` Matthieu Dubuget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1975ba84-1540-ab23-40f0-307420e905a9@gmail.com \
--to=matthieu.dubuget@gmail.com \
--cc=caml-list@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).