* [Caml-list] Flexlink/MinGW/Ctypes linking problem
@ 2017-07-19 6:55 Matthieu Dubuget
2017-07-19 8:29 ` Nicolás Ojeda Bär
0 siblings, 1 reply; 3+ messages in thread
From: Matthieu Dubuget @ 2017-07-19 6:55 UTC (permalink / raw)
To: Caml-list
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
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Flexlink/MinGW/Ctypes linking problem
2017-07-19 6:55 [Caml-list] Flexlink/MinGW/Ctypes linking problem Matthieu Dubuget
@ 2017-07-19 8:29 ` Nicolás Ojeda Bär
2017-07-21 9:13 ` Matthieu Dubuget
0 siblings, 1 reply; 3+ messages in thread
From: Nicolás Ojeda Bär @ 2017-07-19 8:29 UTC (permalink / raw)
To: matthieu.dubuget; +Cc: Caml-list
[-- Attachment #1: Type: text/plain, Size: 3870 bytes --]
Hi Matthieu,
Googling "No master relocation table" leads to https://caml.inria.fr/manti
s/view.php?id=5613 which seems vaguely relevant.
On the other hand, I think Ctypes' dlsym is unrelated to flexlink so I am
not sure it is related.
To get oriented, maybe it is worth doing a "hello world" experiment with
some extern "C" function in a dll and try to call it using Ctypes on
Windows.
Best wishes,
Nicolas
On Wed, Jul 19, 2017 at 8:55 AM, Matthieu Dubuget <
matthieu.dubuget@gmail.com> wrote:
> 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
>
>
> --
> Caml-list mailing list. Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
[-- Attachment #2: Type: text/html, Size: 4961 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [Caml-list] Flexlink/MinGW/Ctypes linking problem
2017-07-19 8:29 ` Nicolás Ojeda Bär
@ 2017-07-21 9:13 ` Matthieu Dubuget
0 siblings, 0 replies; 3+ messages in thread
From: Matthieu Dubuget @ 2017-07-21 9:13 UTC (permalink / raw)
To: Nicolás Ojeda Bär; +Cc: Caml-list
Thanks to Nicolás comments, I found a compromise solution.
Instead of making a CMXA library and using it afterwards, I'm compiling my application directly.
I'm not sure yet about the origin of the problem?
- it may be because my CPP stub is statically linked
- or because I wrote the stubs directly instead of using Ctypes
Best regards
--
Matthieu Dubuget
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2017-07-21 9:52 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-19 6:55 [Caml-list] Flexlink/MinGW/Ctypes linking problem Matthieu Dubuget
2017-07-19 8:29 ` Nicolás Ojeda Bär
2017-07-21 9:13 ` Matthieu Dubuget
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).