www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Talking to non-D libraries

reply Richard Heyes <Richard_member pathlink.com> writes:
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.
Feb 18 2006
parent reply clayasaurus <clayasaurus gmail.com> writes:
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.
 
 
Feb 18 2006
parent reply Richard Heyes <richardh phpguru.org> writes:
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
Feb 18 2006
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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.
Feb 18 2006
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
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
Feb 18 2006
parent reply "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"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 :)
Feb 18 2006
next sibling parent reply Richard Heyes <richardh phpguru.org> writes:
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.
the .so/.dll, but there doesn't appear to be such an option with dmd. Cheers. -- Richard Heyes
Feb 18 2006
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Richard Heyes wrote:


 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
Feb 18 2006
prev sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
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.
Feb 18 2006
parent reply Chris <central_p hotmail.com> writes:
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.
Feb 19 2006
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Chris wrote:

 I'm trying to use the SDL lib from your site but I get: Not a valid
 library file.
Actually I'm not sure if I put the DMC or the original Win lib there... Murphy's states that whatever it is for, it's probably not yours :-) However, the real deal should be available from http://www.libsdl.org/ --anders
Feb 20 2006
next sibling parent reply Chris <central_p hotmail.com> writes:
Thanks,

I've tried the original .libs too they also cannot be recognized.

I cannot understand how to deal with .libs for now.

I've tried the version found here: http://shinh.skr.jp/d/porting.html 
and it works. Then there is a SDL_image.d file but no lib for it and I 
cannot make it link in any way.

I've opened the lib files (but not with a HEX editor) and I saw there is 
the following difference: the original have this at the beginning of the 
file:

!<arch>
/               1100558372              0       1248

The other one and the one I've tried to generate with lib.exe - don't, 
they have something like:

ð

I'm reading this:
http://www.digitalmars.com/d/interfaceToC.html
http://www.digitalmars.com/d/htomodule.html

And I still don't understand what to do ;).

Regards,

     Chris

 Actually I'm not sure if I put the DMC or the original Win lib there...
 Murphy's states that whatever it is for, it's probably not yours :-)
 
 However, the real deal should be available from http://www.libsdl.org/
 
 --anders
Feb 20 2006
next sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Chris wrote:

 I've tried the original .libs too they also cannot be recognized.
If you want to use them with DMC/DMD, you need to convert them first. There should be a tool to do this for you: ftp://ftp.digitalmars.com/coffimplib.zip
 I've tried the version found here: http://shinh.skr.jp/d/porting.html 
 and it works. Then there is a SDL_image.d file but no lib for it and I 
 cannot make it link in any way.
You need to convert the original library then, for use with DMC/DMD. It can be found from here: http://www.libsdl.org/projects/SDL_image/
 I'm reading this:
 http://www.digitalmars.com/d/interfaceToC.html
 http://www.digitalmars.com/d/htomodule.html
 
 And I still don't understand what to do ;).
That's OK, but please give your OS and D compiler next time... http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial/BugReports --anders
Feb 20 2006
parent reply Chris <central_p hotmail.com> writes:
 That's OK, but please give your OS and D compiler next time...
 http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial/BugReports
Sorry, I usually forget to do it. As I said already: I currently use DMD on Windows. I have also installed Cygwin GDC but it requires the cygwin.dll so I prefer DMD for linux and I'm scared to compiles source files :) at least on Windows, so I haven't tryied to compile MingGW with D support. Later on, I'll try D on Linux but for now I want to start with D as soon as possible. I use Code::Blocks as na IDE and unfortunately I do not have much time to try out things. I see you have converted the OpenGL headers, was it difficult are there any special cases? For OpenGL I use GLEW (http://glew.sourceforge.net/) and I might try to convert it. That's why I'm asking.
Feb 20 2006
next sibling parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Chris wrote:

 Sorry, I usually forget to do it. As I said already: I currently use DMD 
 on Windows. I have also installed Cygwin GDC but it requires the 
 cygwin.dll so I prefer DMD for linux and I'm scared to compiles source 
 files :) at least on Windows, so I haven't tryied to compile MingGW with 
 D support.
I'm dabbling with GDC under MinGW myself, will package it if I succeed
 I see you have converted the OpenGL headers, was it difficult are there 
 any special cases?
Not too many, I have a perl script that did most of the translating.
 For OpenGL I use GLEW (http://glew.sourceforge.net/) and I might try to 
 convert it. That's why I'm asking.
It said "C++" on the box, so it might be somewhat trickier. Try it :-) --anders
Feb 20 2006
parent reply Cris <central_p hotmail.com> writes:
 I'm dabbling with GDC under MinGW myself, will package it if I succeed
 
:) If you release MinGW packaged + a working gdb, that'd be great! You might help spreading a good language to the poor old world.
 I see you have converted the OpenGL headers, was it difficult are 
 there any special cases?
Not too many, I have a perl script that did most of the translating.
 For OpenGL I use GLEW (http://glew.sourceforge.net/) and I might try 
 to convert it. That's why I'm asking.
It said "C++" on the box, so it might be somewhat trickier. Try it :-)
I think it is C just as OpenGL.h is but it is enormous almost 1Mb of code.
 I've tried the original .libs too they also cannot be recognized.
If you want to use them with DMC/DMD, you need to convert them first. There should be a tool to do this for you: ftp://ftp.digitalmars.com/coffimplib.zip
Thank you! Now I've managed to link SDL_image.lib but now I have this error: Error 42: Symbol Undefined __init_6events9SDL_Event I see you have discussed it in another thread with another Chris (I'll change my name to Cris now). I've downloaded the packaged 1.2.8 version, because I don't usually use cvs but it seems I have to download a client now.
Feb 20 2006
parent reply =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Cris wrote:
  Error 42: Symbol Undefined __init_6events9SDL_Event
 
 I see you have discussed it in another thread with another Chris (I'll 
 change my name to Cris now).
That's from the D wrapper. Just include sdl/*.d as well. --anders
Feb 20 2006
parent Cris <central_p hotmail.com> writes:
Anders F Björklund wrote:
 Cris wrote:
  Error 42: Symbol Undefined __init_6events9SDL_Event

 I see you have discussed it in another thread with another Chris (I'll 
 change my name to Cris now).
That's from the D wrapper. Just include sdl/*.d as well. --anders
Hmmm, how do you mean I should include sdl/*.d as well? (Note: I use Code::Blocks IDE to compile and I don't know what parameters it passes to DMD.exe) I've already have "import SDL" or you mean I have to import all .d files in the project? I have to try that.
Feb 20 2006
prev sibling parent reply Ivan Senji <ivan.senji_REMOVE_ _THIS__gmail.com> writes:
Chris wrote:
 
 That's OK, but please give your OS and D compiler next time...
 http://www.prowiki.org/wiki4d/wiki.cgi?D__Tutorial/BugReports
Sorry, I usually forget to do it. As I said already: I currently use DMD on Windows. I have also installed Cygwin GDC but it requires the cygwin.dll so I prefer DMD for linux and I'm scared to compiles source files :) at least on Windows, so I haven't tryied to compile MingGW with D support. Later on, I'll try D on Linux but for now I want to start with D as soon as possible. I use Code::Blocks as na IDE and unfortunately I do not have much time to try out things. I see you have converted the OpenGL headers, was it difficult are there any special cases? For OpenGL I use GLEW (http://glew.sourceforge.net/) and I might try to convert it. That's why I'm asking
Don't know if it helps but http://glfw.sourceforge.net/ has import files for D.
Feb 20 2006
parent Chris <central_p hotmail.com> writes:
 Don't know if it helps but http://glfw.sourceforge.net/ has import files 
 for D.
Yes it's interesting but it doesn't seem to support OpenGL 2.0
Feb 20 2006
prev sibling parent clayasaurus <clayasaurus gmail.com> writes:
Have you tried the derelict project on dsource.org? It is good for both 
linux and windows, it will load .dll and .so files at runtime so you 
don't have to mess with .lib formats.

Chris wrote:
 Thanks,
 
 I've tried the original .libs too they also cannot be recognized.
 
 I cannot understand how to deal with .libs for now.
 
 I've tried the version found here: http://shinh.skr.jp/d/porting.html 
 and it works. Then there is a SDL_image.d file but no lib for it and I 
 cannot make it link in any way.
 
 I've opened the lib files (but not with a HEX editor) and I saw there is 
 the following difference: the original have this at the beginning of the 
 file:
 
 !<arch>
 /               1100558372              0       1248
 
 The other one and the one I've tried to generate with lib.exe - don't, 
 they have something like:
 
 ð
 
 I'm reading this:
 http://www.digitalmars.com/d/interfaceToC.html
 http://www.digitalmars.com/d/htomodule.html
 
 And I still don't understand what to do ;).
 
 Regards,
 
     Chris
 
 Actually I'm not sure if I put the DMC or the original Win lib there...
 Murphy's states that whatever it is for, it's probably not yours :-)

 However, the real deal should be available from http://www.libsdl.org/

 --anders
Feb 20 2006
prev sibling parent reply Chris <central_p hotmail.com> writes:
Sorry I forgot this:

Are lib files dependent of the platform? (I use Windows for now, later 
also I'll be try Linux too).
Feb 20 2006
parent =?ISO-8859-1?Q?Anders_F_Bj=F6rklund?= <afb algonet.se> writes:
Chris wrote:

 Are lib files dependent of the platform? (I use Windows for now, later 
 also I'll be try Linux too).
Yes, they depend on both the platform and the compiler... Fortunately it is easier on Linux, since you can link to the dynamic library directly and almost everyone uses GCC. --anders
Feb 20 2006