www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Linking to static libraries

reply "Minas" <minas_mina1990 hotmail.co.uk> writes:
I have a static library (libDerelictSDL2.a) in 
/usr/lib/Derelict3. What I want to to is just link to that. My 
code does not use anything from it.

My .d file is icy.d.

I try to compile using:

a) dmd icy.d -I/usr/lib/Derelict3 -L-lDerelictSDL2
b) dmd icy.d -L-I/usr/lib/Derelict3 -L-lDerelictSDL2
c) dmd icy.d -L-lDerelictSDL2

None works, and the error is:



/usr/bin/ld: cannot find -lDerelictSDL2
collect2: ld returned 1 exit status
--- errorlevel 1

Why can't it find it? I have set the linker's path correctly (I 
think).
May 10 2012
next sibling parent reply Jacob Carlborg <doob me.com> writes:
On 2012-05-10 14:55, Minas wrote:
 I have a static library (libDerelictSDL2.a) in /usr/lib/Derelict3. What
 I want to to is just link to that. My code does not use anything from it.

 My .d file is icy.d.

 I try to compile using:

 a) dmd icy.d -I/usr/lib/Derelict3 -L-lDerelictSDL2
 b) dmd icy.d -L-I/usr/lib/Derelict3 -L-lDerelictSDL2
 c) dmd icy.d -L-lDerelictSDL2

 None works, and the error is:



 /usr/bin/ld: cannot find -lDerelictSDL2
 collect2: ld returned 1 exit status
 --- errorlevel 1

 Why can't it find it? I have set the linker's path correctly (I think).

Try: $ dmd icy.d -L-L/usr/lib/Derelict3 -L-lDerelictSDL2 You can also supply the library directly: $ dmd icy.d /usr/lib/Derelict3/DerelictSDL2 -- /Jacob Carlborg
May 10 2012
parent Jacob Carlborg <doob me.com> writes:
On 2012-05-10 15:21, Minas wrote:

 $ dmd icy.d /usr/lib/Derelict3/DerelictSDL2

 This doesn't because dmd thinks that I'm talking about a .d file.

Hmm, that wasn't quite right, try this: $ dmd icy.d /usr/lib/Derelict3/libDerelictSDL2.a (Or whatever the full path to the library is) -- /Jacob Carlborg
May 10 2012
prev sibling next sibling parent "Minas" <minas_mina1990 hotmail.co.uk> writes:
On Thursday, 10 May 2012 at 13:14:36 UTC, Jacob Carlborg wrote:
 On 2012-05-10 14:55, Minas wrote:
 I have a static library (libDerelictSDL2.a) in 
 /usr/lib/Derelict3. What
 I want to to is just link to that. My code does not use 
 anything from it.

 My .d file is icy.d.

 I try to compile using:

 a) dmd icy.d -I/usr/lib/Derelict3 -L-lDerelictSDL2
 b) dmd icy.d -L-I/usr/lib/Derelict3 -L-lDerelictSDL2
 c) dmd icy.d -L-lDerelictSDL2

 None works, and the error is:



 /usr/bin/ld: cannot find -lDerelictSDL2
 collect2: ld returned 1 exit status
 --- errorlevel 1

 Why can't it find it? I have set the linker's path correctly 
 (I think).

Try: $ dmd icy.d -L-L/usr/lib/Derelict3 -L-lDerelictSDL2 You can also supply the library directly: $ dmd icy.d /usr/lib/Derelict3/DerelictSDL2

Thank you very much!!
 $ dmd icy.d -L-L/usr/lib/Derelict3 -L-lDerelictSDL2

This works fine! $ dmd icy.d /usr/lib/Derelict3/DerelictSDL2 This doesn't because dmd thinks that I'm talking about a .d file.
May 10 2012
prev sibling next sibling parent "Minas" <minas_mina1990 hotmail.co.uk> writes:
I figured it out, this is the correct:

-L-L/usr/lib/Derelict2 -L-lDerelictSDL -L-lDerelictUtil -L-ldl

I don't know why, but the dl library is needed. Thank you for 
your help.
May 10 2012
prev sibling parent "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Thu, May 10, 2012 at 09:00:02PM +0200, Minas wrote:
 I figured it out, this is the correct:
 
 -L-L/usr/lib/Derelict2 -L-lDerelictSDL -L-lDerelictUtil -L-ldl
 
 I don't know why, but the dl library is needed. Thank you for your
 help.

This is most likely because Derelict uses dynamic loading of modules at runtime. T -- If the comments and the code disagree, it's likely that *both* are wrong. -- Christopher
May 10 2012