digitalmars.D.learn - D with gmp via swig
- Oliver (34/34) Aug 14 2011 Hello I am trying to get to a gmp interface for D2. I have some trouble ...
- Iain Buclaw (6/36) Aug 14 2011 This will be a bug in swig. Whatever storage class it is setting
- Oliver (3/3) Aug 14 2011 Thanks Iain,
- David Nadlinger (6/11) Aug 14 2011 SWIG currently only supports dynamically loading the wrapper library.
- Caligo (1/1) Aug 14 2011 Shouldn't there be an interface to GMP and MPFR in Phobos by default?
- Oliver (13/13) Aug 14 2011 Thanks David,
- David Nadlinger (7/8) Aug 14 2011 You don't need to link the .so in (although I'm surprised to see that it...
- Oliver (6/14) Aug 14 2011 David, thanks this seems to work.
- David Nadlinger (6/8) Aug 14 2011 Alternatively, you could set LD_LIBRARY_PATH to where your library
- Oliver (6/14) Aug 14 2011 David, I do not have any preference - I think, however, as a quick fix, ...
- Andrej Mitrovic (2/2) Aug 14 2011 This seems ancient, but maybe it could help:
Hello I am trying to get to a gmp interface for D2. I have some trouble to get that to work, however. Perhaps someone has an idea what I am doing wrong. I must admit I am not sure this is a D issue or a swig issue or something else. The interface file for swig cat gmpd.i %module gmpd %{ #include "gmp.h" %} %include "gmp.h" A main with a call to gmpd cat main.d import std.stdio; import gmpd; void main() { writeln("Hello"); } This is what I do then: /usr/local/swig-204/bin/swig -I/usr/include/ -d -d2 gmpd.i /opt/usr/local/bin/gdc -c main.d /opt/usr/local/bin/gdc -c gmpd.d /opt/usr/local/bin/gdc -c gmpd_im.d /opt/usr/local/bin/gdc -c gmpd_wrap.c /opt/usr/local/bin/gdc main.o -oa.out gmpd.o gmpd_im.o gmpd_wrap.o -lgmp I get messages of the type: /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/ld: __gmp_set_memory_functions: TLS definition in gmpd_im.o section .tbss mismatches non-TLS reference in gmpd_wrap.o gmpd_wrap.o: could not read symbols: Bad value collect2: ld returned 1 exit status I have tried dmd and/or gcc (for the wrapper compilation and linking) but no joy. Also -fPIC did not help. Thanks, Oliver
Aug 14 2011
== Quote from Oliver (oliver.ruebenkoenig web.de)'s articleHello I am trying to get to a gmp interface for D2. I have some trouble to get that to work, however. Perhaps someone has an idea what I am doing wrong. I must admit I am not sure this is a D issue or a swig issue or something else. The interface file for swig cat gmpd.i %module gmpd %{ #include "gmp.h" %} %include "gmp.h" A main with a call to gmpd cat main.d import std.stdio; import gmpd; void main() { writeln("Hello"); } This is what I do then: /usr/local/swig-204/bin/swig -I/usr/include/ -d -d2 gmpd.i /opt/usr/local/bin/gdc -c main.d /opt/usr/local/bin/gdc -c gmpd.d /opt/usr/local/bin/gdc -c gmpd_im.d /opt/usr/local/bin/gdc -c gmpd_wrap.c /opt/usr/local/bin/gdc main.o -oa.out gmpd.o gmpd_im.o gmpd_wrap.o -lgmp I get messages of the type: /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/bin/ld: __gmp_set_memory_functions: TLS definition in gmpd_im.o section .tbss mismatches non-TLS reference in gmpd_wrap.o gmpd_wrap.o: could not read symbols: Bad value collect2: ld returned 1 exit statusThis will be a bug in swig. Whatever storage class it is setting __gmp_set_memory_functions, it is wrong (I assume it should be defining it as __gshared). Regards Iain
Aug 14 2011
Thanks Iain, I'll contact the swig team about it. Oliver
Aug 14 2011
On 8/14/11 1:29 PM, Oliver wrote:Hello I am trying to get to a gmp interface for D2. I have some trouble to get that to work, however. Perhaps someone has an idea what I am doing wrong. I must admit I am not sure this is a D issue or a swig issue or something else. […] /opt/usr/local/bin/gdc main.o -oa.out gmpd.o gmpd_im.o gmpd_wrap.o -lgmpSWIG currently only supports dynamically loading the wrapper library. Drop -lgmp and gmpd_wrap.o when linking the D executable and compile a shared library (.so, .dylib/.bundle, .dll) out of the wrapper code instead (by default, the name would be libgmpd_wrap.<ext>). David
Aug 14 2011
Shouldn't there be an interface to GMP and MPFR in Phobos by default?
Aug 14 2011
Thanks David, so when I gcc -fPIC -c gmpd_wrap.c gcc -shared -Wl,-soname,libgmpd_wrap.so.1 -o libgmpd_wrap.so.1.0.1 gmpd_wrap.o -lgmp ln -s libgmpd_wrap.so.1.0.1 libgmpd_wrap.so /opt/usr/local/bin/gdc main.d gmpd.d gmpd_im.d -I. -L. -lgmpd_wrap I get the /usr/bin/ld: __gmpn_ior_n: TLS definition in /tmp/ccmF49fr.o section .tbss mismatches non-TLS reference in ./libgmpd_wrap.so ./libgmpd_wrap.so: could not read symbols: Bad value collect2: ld returned 1 exit status again, a mismatch. Oliver
Aug 14 2011
On 8/14/11 2:34 PM, Oliver wrote:/opt/usr/local/bin/gdc main.d gmpd.d gmpd_im.d -I. -L. -lgmpd_wrapYou don't need to link the .so in (although I'm surprised to see that it produces linker errors, I didn't remember that there are name collisions with the default settings), it will be loaded at runtime. This decision was made to easily support Windows, where the COFF/OMF situation complicates matters a lot… David
Aug 14 2011
== Quote from David Nadlinger (see klickverbot.at)'s articleOn 8/14/11 2:34 PM, Oliver wrote:David, thanks this seems to work. /opt/usr/local/bin/gdc main.d gmpd.d gmpd_im.d I did have to copy the libgmpd_wrap* to some place were the linker could find it, of course. Oliver/opt/usr/local/bin/gdc main.d gmpd.d gmpd_im.d -I. -L. -lgmpd_wrapYou don't need to link the .so in (although I'm surprised to see that it produces linker errors, I didn't remember that there are name collisions with the default settings), it will be loaded at runtime. This decision was made to easily support Windows, where the COFF/OMF situation complicates matters a lot… David
Aug 14 2011
On 8/14/11 3:03 PM, Oliver wrote:I did have to copy the libgmpd_wrap* to some place were the linker could find it, of course.Alternatively, you could set LD_LIBRARY_PATH to where your library resides. If there is demand, I could definitely look into adding static linking support to SWIG (it is on the TODO list already), but currently, I'm rather busy with my Thrift GSoC project. David
Aug 14 2011
== Quote from David Nadlinger (see klickverbot.at)'s articleOn 8/14/11 3:03 PM, Oliver wrote:David, I do not have any preference - I think, however, as a quick fix, it might be beneficial to add the current status, that a) you need dynamic linking and b) that -L. -lgmpd_wrap does not work as expected to the documentation. That would have helped me. OliverI did have to copy the libgmpd_wrap* to some place were the linker could find it, of course.Alternatively, you could set LD_LIBRARY_PATH to where your library resides. If there is demand, I could definitely look into adding static linking support to SWIG (it is on the TODO list already), but currently, I'm rather busy with my Thrift GSoC project. David
Aug 14 2011
This seems ancient, but maybe it could help: http://www.dsource.org/projects/bindings/browser/trunk/gmp
Aug 14 2011