Thread overview | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
February 18, 2006 Talking to non-D libraries | ||||
---|---|---|---|---|
| ||||
Can anyone point me to a laymans guide to how I would talk to a non D library, for example sqlite.so. I've managed so far to use (for example) getpid() like so: extern (C) { int getpid(); } But what about other libraries? Thanks. |
February 18, 2006 Re: Talking to non-D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Heyes | http://www.digitalmars.com/d/interfaceToC.html ? Richard Heyes wrote: > Can anyone point me to a laymans guide to how I would talk to a non D library, > for example sqlite.so. > > I've managed so far to use (for example) getpid() like so: > > extern (C) { > int getpid(); > } > > But what about other libraries? > > Thanks. > > |
February 18, 2006 Re: Talking to non-D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to clayasaurus | clayasaurus wrote: > http://www.digitalmars.com/d/interfaceToC.html ? Thanks. Isn't there also a requirement to tell the compiler to link against the external .so? Cheers. -- Richard Heyes |
February 18, 2006 Re: Talking to non-D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Heyes | "Richard Heyes" <richardh@phpguru.org> wrote in message news:dt7ito$2en4$1@digitaldaemon.com... > clayasaurus wrote: >> http://www.digitalmars.com/d/interfaceToC.html ? > > Thanks. Isn't there also a requirement to tell the compiler to link against the external .so? You can use implib to generate an "import library" for a dynamically linked library. The generated import library can then be linked with your program so the linker will know where to find the functions. I'm pretty sure implib exists in *nix. I'd be very surprised if it didn't. |
February 18, 2006 Re: Talking to non-D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
> You can use implib to generate an "import library" for a dynamically linked library. The generated import library can then be linked with your program so the linker will know where to find the functions. I'm pretty sure implib exists in *nix. I'd be very surprised if it didn't.
It's normally not needed, you can link with the dynamic lib directly.
--anders
|
February 18, 2006 Re: Talking to non-D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | "Anders F Björklund" <afb@algonet.se> wrote in message news:dt7qtn$2ktg$1@digitaldaemon.com... > It's normally not needed, you can link with the dynamic lib directly. Really! That's news to me :) |
February 18, 2006 Re: Talking to non-D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote: > "Anders F Björklund" <afb@algonet.se> wrote in message news:dt7qtn$2ktg$1@digitaldaemon.com... > >>It's normally not needed, you can link with the dynamic lib directly. Ummm, how? With the C# compiler there's a command line flag to specify the .so/.dll, but there doesn't appear to be such an option with dmd. Cheers. -- Richard Heyes |
February 18, 2006 Re: Talking to non-D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Jarrett Billingsley | Jarrett Billingsley wrote:
>>It's normally not needed, you can link with the dynamic lib directly.
>
> Really! That's news to me :)
A common approach is that you have one "versioned" shared library:
libfoo.so.1.2.3
libfoo.1.2.3.dylib
And then you have one "developer" library, which is just a symlink:
libfoo.so -> libfoo.so.1.2.3
libfoo.dylib -> libfoo.1.2.3.dylib
Then you can use "-lfoo" flag to link, it'll pick the current version.
Your binary will end up requiring the correct 1.2.3 version at runtime.
--anders
PS. ".so" are being used in e.g. Linux, and ".dylib" in Darwin/Mac.
|
February 18, 2006 Re: Talking to non-D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Richard Heyes | Richard Heyes wrote:
> Ummm, how? With the C# compiler there's a command line flag to specify
> the .so/.dll, but there doesn't appear to be such an option with dmd.
Either with the full library path, or by using the "-L-lfoo" syntax.
GDC uses the GCC syntax: -lfoo
--anders
|
February 20, 2006 Re: Talking to non-D libraries | ||||
---|---|---|---|---|
| ||||
Posted in reply to Anders F Björklund | I'm trying to use the SDL lib from your site but I get: Not a valid
library file.
Anders F Björklund wrote:
> Jarrett Billingsley wrote:
>
>>> It's normally not needed, you can link with the dynamic lib directly.
>>
>> Really! That's news to me :)
>
> A common approach is that you have one "versioned" shared library:
>
> libfoo.so.1.2.3
> libfoo.1.2.3.dylib
>
> And then you have one "developer" library, which is just a symlink:
>
> libfoo.so -> libfoo.so.1.2.3
> libfoo.dylib -> libfoo.1.2.3.dylib
>
> Then you can use "-lfoo" flag to link, it'll pick the current version.
> Your binary will end up requiring the correct 1.2.3 version at runtime.
>
> --anders
>
>
> PS. ".so" are being used in e.g. Linux, and ".dylib" in Darwin/Mac.
|
Copyright © 1999-2021 by the D Language Foundation