www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - linking external libs

reply "Nicholas Wilson" <iamthewilsonator hotmail.com> writes:
So test.d depends on libgmp.a

Unsurprisingly:
$dmd test.d
  fails to find libgmp.a

So tell it  to look
$dmd  -L-lgmp test.d

finds the wrong one or doesn't find it.

Tell it where to look

$dmd -L-L/usr/local/lib -L-lgmp test.d

Ok. Now it fails to find Phobos. Ok

$dmd -L-L/usr/local/lib -L-L/usr/share/dmd/lib -L-lgmp 
-L-lphobos2 test.d

... still fails to find Phobos. WTF? is there a way out of this 
revolving door?

reordering the linker flags doesn't seem to help.

Also is there a binding to GMP somewhere? I just hacked one 
together.

-Nic
Jul 02 2015
next sibling parent reply Steven Schveighoffer <schveiguy yahoo.com> writes:
On 7/2/15 8:10 AM, Nicholas Wilson wrote:
 So test.d depends on libgmp.a

 Unsurprisingly:
 $dmd test.d
   fails to find libgmp.a

 So tell it  to look
 $dmd  -L-lgmp test.d

 finds the wrong one or doesn't find it.

 Tell it where to look

 $dmd -L-L/usr/local/lib -L-lgmp test.d

 Ok. Now it fails to find Phobos. Ok

 $dmd -L-L/usr/local/lib -L-L/usr/share/dmd/lib -L-lgmp -L-lphobos2 test.d

 .... still fails to find Phobos. WTF? is there a way out of this
 revolving door?

 reordering the linker flags doesn't seem to help.

 Also is there a binding to GMP somewhere? I just hacked one together.
Try dmd -v, it will tell you the link line. Then you can try it yourself to see how to get it to work. I know dmd has problems with link line parameters, because it always puts Phobos somewhere. But this is generally for libraries that Phobos needs, not user code. A full example may be useful too. -Steve
Jul 02 2015
parent reply "Nicholas Wilson" <iamthewilsonator hotmail.com> writes:
On Thursday, 2 July 2015 at 12:19:06 UTC, Steven Schveighoffer 
wrote:
 On 7/2/15 8:10 AM, Nicholas Wilson wrote:
 [...]
Try dmd -v, it will tell you the link line. Then you can try it yourself to see how to get it to work. I know dmd has problems with link line parameters, because it always puts Phobos somewhere. But this is generally for libraries that Phobos needs, not user code. A full example may be useful too. -Steve
linker command is gcc test2.o -o test -m64 -L/usr/share/dmd/lib -L/usr/local/lib -lgmp -lphobos2 -L/Users/nicholaswilson/d/lib/ -lphobos2 -lpthread -lm
Jul 02 2015
next sibling parent "FreeSlave" <freeslave93 gmail.com> writes:
On Thursday, 2 July 2015 at 12:47:52 UTC, Nicholas Wilson wrote:
 On Thursday, 2 July 2015 at 12:19:06 UTC, Steven Schveighoffer 
 wrote:
 On 7/2/15 8:10 AM, Nicholas Wilson wrote:
 [...]
Try dmd -v, it will tell you the link line. Then you can try it yourself to see how to get it to work. I know dmd has problems with link line parameters, because it always puts Phobos somewhere. But this is generally for libraries that Phobos needs, not user code. A full example may be useful too. -Steve
linker command is gcc test2.o -o test -m64 -L/usr/share/dmd/lib -L/usr/local/lib -lgmp -lphobos2 -L/Users/nicholaswilson/d/lib/ -lphobos2 -lpthread -lm
Are you on OSX? (I consider it from /Users instead of /home) Try export LIBRARY_PATH=/usr/local/lib. Can you build C application linked to libgmp this way?
Jul 02 2015
prev sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 7/2/15 8:47 AM, Nicholas Wilson wrote:
 On Thursday, 2 July 2015 at 12:19:06 UTC, Steven Schveighoffer wrote:
 On 7/2/15 8:10 AM, Nicholas Wilson wrote:
 [...]
Try dmd -v, it will tell you the link line. Then you can try it yourself to see how to get it to work. I know dmd has problems with link line parameters, because it always puts Phobos somewhere. But this is generally for libraries that Phobos needs, not user code. A full example may be useful too. -Steve
linker command is gcc test2.o -o test -m64 -L/usr/share/dmd/lib -L/usr/local/lib -lgmp -lphobos2 -L/Users/nicholaswilson/d/lib/ -lphobos2 -lpthread -lm
OK, but what I meant was, run this line yourself and see if you can get it to link by tweaking things :) D isn't doing anything magic here. And without full code/environment, it's impossible to tell you why this doesn't work. -Steve
Jul 02 2015
prev sibling parent "qznc" <qznc web.de> writes:
On Thursday, 2 July 2015 at 12:10:52 UTC, Nicholas Wilson wrote:
 Also is there a binding to GMP somewhere? I just hacked one 
 together.
I could need the bindings to fix the pidigits benchmark. There is this 7y old code on dsource: http://www.dsource.org/projects/bindings/browser/trunk/gmp The readme says "This is in alpha state. All functions that have been tried seem to work. (8 out of many)", so not that confident.
Aug 29 2015