View previous topic :: View next topic |
Author |
Message |
jamasan
Joined: 12 Dec 2006 Posts: 1
|
Posted: Tue Dec 12, 2006 2:53 pm Post subject: Building libraries in D |
|
|
I'm relatively new to D, so forgive my ignorance. I'm interested in building a library for D. But there are a few things I'm not quite clear on.
From the changelog it seems that Bud can build shared libraries (so) under Linux. But I don't see how to change the target type from static to shared. Does D even support shared libs?
The other thing I am not clear on is the matter of "headers" or lack there of. I see many mentions of placing library source files in src/ext or similar - does one have to include the full source of the library in order to build against it?
(I'm using gdc under Linux). Thanks in advance. |
|
Back to top |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Tue Dec 12, 2006 3:05 pm Post subject: Re: Building libraries in D |
|
|
jamasan wrote: | I'm relatively new to D, so forgive my ignorance. I'm interested in building a library for D. But there are a few things I'm not quite clear on.
From the changelog it seems that Bud can build shared libraries (so) under Linux. But I don't see how to change the target type from static to shared. Does D even support shared libs?
|
I'm sorry but I don't thik that the creation of shared linux libraries are supported yet by gdc or dmd.
jamasan wrote: | The other thing I am not clear on is the matter of "headers" or lack there of. I see many mentions of placing library source files in src/ext or similar - does one have to include the full source of the library in order to build against it?
|
No, you do not have to use the full source of a module to build using the module in a library. You create a 'header' version of the module source file. You can do this automatically with dmd using the -H switch - this creates a D interface file which is really a 'header' file. Alternatively you can do one by hand - just identify the public symbols and remove the implementation stuff.
eg.
Code: |
int foo(short a, char[] b) {
b[a] = ' ';
}
|
becomes
Code: |
int foo(short, char[]);
|
In order to have both the implementation and the header file in the same -I scope, change the file extention to ".di" for the header file and place them in a different location then point to them using a -I switch. _________________ --
Derek
skype name: derek.j.parnell |
|
Back to top |
|
|
marcio
Joined: 04 May 2007 Posts: 2 Location: Lisbon, Portugal
|
Posted: Fri May 04, 2007 2:10 pm Post subject: Building libraries on Windows |
|
|
Hi,
How can I build a library? For example, I have two files:
Code: | // main.d
import std.stdio;
void main() {
writefln("main");
}
// test.d
void test() {
} |
So, to create a library I do this:
Code: | bud main.d -clean -lib
bud test.d -clean -link main.lib |
The first command runs just fine, but the second one says:
Quote: | OPTLINK (R) for Win32 Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved
OPTLINK : Warning 23: No Stack
OPTLINK : Warning 134: No Start Address
|
Am I doing something wrong?
Thanks,
P.S.: I'm using Bud v3.04 and DMD v1.014 on Windows XP. |
|
Back to top |
|
|
Derek Parnell
Joined: 22 Apr 2004 Posts: 408 Location: Melbourne, Australia
|
Posted: Fri May 04, 2007 11:41 pm Post subject: |
|
|
Ok, I think I can see what you are trying to do.
You want to have a library that contains the 'main' entry point for a program and you want to compile other programs that do not specify 'main' but link in the 'main' library instead.
This is not a Bud issue. This is a problem with DMD. I don't know how to force DMD's linker to do what you want, but I'll do some more research etc ...
Here is how I think it should be done using just DMD...
Code: |
dmd main.d -c
lib -c -l main.lib main.obj
dmd test.d main.lib
|
but as you note, the linker doesn't recognize the stack address and start address. _________________ --
Derek
skype name: derek.j.parnell |
|
Back to top |
|
|
marcio
Joined: 04 May 2007 Posts: 2 Location: Lisbon, Portugal
|
Posted: Sat May 05, 2007 2:30 am Post subject: |
|
|
Hi Derek,
I thought it was a problem with Bud, but now I see it isn't
Thanks anyway |
|
Back to top |
|
|
|