www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - linking with a C library

reply Oliver <Oliver_member pathlink.com> writes:
Hello !

I want to use a C library lib*.a that has been compiled with gcc
 I have 3 D-modules that declare all the functions in
the library like this :

version(Linux) {

extern(C):

}

..List of data types and functions ....

How do I compile and link if I want to make use of the library ?

regards, oliver
May 11 2005
next sibling parent reply "Andrew Fedoniouk" <news terrainformatica.com> writes:
 I want to use a C library lib*.a that has been compiled with gcc...
 How do I compile and link if I want to make use of the library ?

As usual with C/C++ 1) compile your library. 2) Link it in your D project using command line parameters or 3) use pragma(lib) in D source code: pragma(lib, "imageio.lib"); Example: http://www.terrainformatica.com/harmonia/imageio.d.zip ( DecodeImage using standard libPNG and libJPEG in D ) Andrew. "Oliver" <Oliver_member pathlink.com> wrote in message news:d5t652$141g$1 digitaldaemon.com...
 Hello !

 I want to use a C library lib*.a that has been compiled with gcc
 I have 3 D-modules that declare all the functions in
 the library like this :

 version(Linux) {

 extern(C):

 }

 ..List of data types and functions ....

 How do I compile and link if I want to make use of the library ?

 regards, oliver

 

May 11 2005
parent reply Dejan Lekic <leka entropy.tmok.com> writes:
 3) use pragma(lib) in D source code:

Does it work on LINUX too? -- ........... Dejan Lekic http://dejan.lekic.org
May 11 2005
parent "Walter" <newshound digitalmars.com> writes:
"Dejan Lekic" <leka entropy.tmok.com> wrote in message
news:d5tfic$1bqo$1 digitaldaemon.com...
 3) use pragma(lib) in D source code:

Does it work on LINUX too?

Not yet.
May 11 2005
prev sibling next sibling parent Lukas Pinkowski <pinkowls informatik.uni-stuttgart.de> writes:
Oliver wrote:

 Hello !
 
 I want to use a C library lib*.a that has been compiled with gcc
  I have 3 D-modules that declare all the functions in
 the library like this :
 
 version(Linux) {
 
 extern(C):
 
 }
 
 ..List of data types and functions ....
 
 How do I compile and link if I want to make use of the library ?
 
 regards, oliver

First of all: Do not compile the modules with the C-declarations! There are basically two possibilities: dmd yourapp.d ... -L-lyourlib This will call gcc automagically, and link with libyourlib.a, (the dots are your other object files) or dmd -c yourapp.d gcc -o yourapp yourapp.o ... -lphobos -lyourlib kind regards, Lukas
May 11 2005
prev sibling parent Oliver <Oliver_member pathlink.com> writes:
In article <d5t652$141g$1 digitaldaemon.com>, Oliver says...
Hello !

I want to use a C library lib*.a that has been compiled with gcc
 I have 3 D-modules that declare all the functions in
the library like this :

version(Linux) {

extern(C):

}

..List of data types and functions ....

How do I compile and link if I want to make use of the library ?

regards, oliver

I did the following :dmd -d boing.d -L-lglfw But I should have done it this way : dmd -d boing.d -L-lglfw -L-lglib -L-lglut -L-lXxf86vm Because the other libs are required by glfw !? That took quite some time - THX for all the answers regards, Oliver
May 11 2005