View mode: basic / threaded / horizontal-split · Log in · Help
May 11, 2005
linking with a C library
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
Re: linking with a C library
> 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
Re: linking with a C library
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
Re: linking with a C library
> 3) use pragma(lib) in D source code:

Does it work on LINUX too?

-- 
...........
Dejan Lekic
 http://dejan.lekic.org
May 11, 2005
linking with a C library works now
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 12, 2005
Re: linking with a C library
"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.
Top | Discussion index | About this forum | D home