FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Building libraries in D

 
Post new topic   Reply to topic     Forum Index -> Build
View previous topic :: View next topic  
Author Message
jamasan



Joined: 12 Dec 2006
Posts: 1

PostPosted: Tue Dec 12, 2006 2:53 pm    Post subject: Building libraries in D Reply with quote

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
View user's profile Send private message
Derek Parnell



Joined: 22 Apr 2004
Posts: 408
Location: Melbourne, Australia

PostPosted: Tue Dec 12, 2006 3:05 pm    Post subject: Re: Building libraries in D Reply with quote

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
View user's profile Send private message
marcio



Joined: 04 May 2007
Posts: 2
Location: Lisbon, Portugal

PostPosted: Fri May 04, 2007 2:10 pm    Post subject: Building libraries on Windows Reply with quote

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
View user's profile Send private message
Derek Parnell



Joined: 22 Apr 2004
Posts: 408
Location: Melbourne, Australia

PostPosted: Fri May 04, 2007 11:41 pm    Post subject: Reply with quote

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
View user's profile Send private message
marcio



Joined: 04 May 2007
Posts: 2
Location: Lisbon, Portugal

PostPosted: Sat May 05, 2007 2:30 am    Post subject: Reply with quote

Hi Derek,

I thought it was a problem with Bud, but now I see it isn't
Thanks anyway Smile
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> Build All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group