www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Linux shared libraries - I'm confused

reply Steve Teale <steve.teale britseyeview.com> writes:
I've seen it said that dmd does not support creation of Linux shared libraries,
but I've also seen it said that you can use dmd -c to create a .o file, and
then use gcc -shared ... to create an so. Can anyone clarify the position here
please?
Aug 16 2007
next sibling parent Steve Teale <steve.teale britseyeview.com> writes:
Steve Teale Wrote:

 I've seen it said that dmd does not support creation of Linux shared
libraries, but I've also seen it said that you can use dmd -c to create a .o
file, and then use gcc -shared ... to create an so. Can anyone clarify the
position here please?
 
Sorry, more specifically, if I try the GCC approach and then try to dynamically load the library, dlopen() reports "/home/teales/d/libgenit.so.1.0.0: undefined symbol: _Dmodule_ref"
Aug 16 2007
prev sibling next sibling parent reply Matthias Walter <walter mail.math.uni-magdeburg.de> writes:
Steve Teale Wrote:

 I've seen it said that dmd does not support creation of Linux shared
libraries, but I've also seen it said that you can use dmd -c to create a .o
file, and then use gcc -shared ... to create an so. Can anyone clarify the
position here please?
 
AFAIK dmd cannot create position independent code. So, you can link it this way but the code is not guaranteed to work. But with gdc you can use -fpic to generate such code. best regards Matthias
Aug 16 2007
parent reply Steve Teale <steve.teale britseyeview.com> writes:
Matthias Walter Wrote:

 Steve Teale Wrote:
 
 I've seen it said that dmd does not support creation of Linux shared
libraries, but I've also seen it said that you can use dmd -c to create a .o
file, and then use gcc -shared ... to create an so. Can anyone clarify the
position here please?
 
AFAIK dmd cannot create position independent code. So, you can link it this way but the code is not guaranteed to work. But with gdc you can use -fpic to generate such code. best regards Matthias
Hmm, well that's a bit of a show-stopper for Linux coding then isn't it. Am I also correct in thinking that GDC does not support D version 2 yet?
Aug 16 2007
parent reply Nicolai Waniek <no.spam thank.you.com> writes:
Steve Teale wrote:
 
 Hmm, well that's a bit of a show-stopper for Linux coding then isn't it. Am I
also correct in thinking that GDC does not support D version 2 yet?
 
I definitley have to say: yes, this is a show-stopper. I'm still waiting for Walter to make it possible to compiler to an .so under Linux... until that, I stopped using D and concentrating on some other projects w/ python. best regards, Nicolai -- .71 nicolai dot waniek at sphere71 dot com
Aug 17 2007
parent reply Gregor Richards <Richards codu.org> writes:
Nicolai Waniek wrote:
 Steve Teale wrote:
 Hmm, well that's a bit of a show-stopper for Linux coding then isn't it. Am I
also correct in thinking that GDC does not support D version 2 yet?
I definitley have to say: yes, this is a show-stopper. I'm still waiting for Walter to make it possible to compiler to an .so under Linux... until that, I stopped using D and concentrating on some other projects w/ python. best regards, Nicolai
What the hell, people, there's an easy solution: Use GDC. - Gregor Richards
Aug 17 2007
next sibling parent reply Tristam MacDonald <swiftcoder gmail.com> writes:
Gregor Richards wrote:
 Nicolai Waniek wrote:
 Steve Teale wrote:
 Hmm, well that's a bit of a show-stopper for Linux coding then isn't 
 it. Am I also correct in thinking that GDC does not support D version 
 2 yet?
I definitley have to say: yes, this is a show-stopper. I'm still waiting for Walter to make it possible to compiler to an .so under Linux... until that, I stopped using D and concentrating on some other projects w/ python. best regards, Nicolai
What the hell, people, there's an easy solution: Use GDC. - Gregor Richards
Not quite as easy as it might be. There seem to be far more pitfalls to getting a working shared library under D than under C. In addition, there is still no 2.0 support in GDC. On a realated note, it would be nice to get libgphobos working as a dynamic library with GDC, and shave a few 100K off of my executables...
Aug 17 2007
next sibling parent reply Gregor Richards <Richards codu.org> writes:
Tristam MacDonald wrote:
 
 
 Gregor Richards wrote:
 Nicolai Waniek wrote:
 Steve Teale wrote:
 Hmm, well that's a bit of a show-stopper for Linux coding then isn't 
 it. Am I also correct in thinking that GDC does not support D 
 version 2 yet?
I definitley have to say: yes, this is a show-stopper. I'm still waiting for Walter to make it possible to compiler to an .so under Linux... until that, I stopped using D and concentrating on some other projects w/ python. best regards, Nicolai
What the hell, people, there's an easy solution: Use GDC. - Gregor Richards
Not quite as easy as it might be. There seem to be far more pitfalls to getting a working shared library under D than under C. In addition, there is still no 2.0 support in GDC.
So long as the standard library is static instead of shared, it will always be more complicated. If the standard library was shared, this would be simple. Oh my god, there's STILL no 2.0 support in GDC after it's existed for almost TWO MONTHS??!?!?! For shame!!! Yeesh.
 
 On a realated note, it would be nice to get libgphobos working as a 
 dynamic library with GDC, and shave a few 100K off of my executables...
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=43626 - Gregor Richards
Aug 17 2007
parent Tristam MacDonald <swiftcoder gmail.com> writes:
Gregor Richards wrote:
 Tristam MacDonald wrote:
 Gregor Richards wrote:
 Nicolai Waniek wrote:
 Steve Teale wrote:
 Hmm, well that's a bit of a show-stopper for Linux coding then 
 isn't it. Am I also correct in thinking that GDC does not support D 
 version 2 yet?
I definitley have to say: yes, this is a show-stopper. I'm still waiting for Walter to make it possible to compiler to an .so under Linux... until that, I stopped using D and concentrating on some other projects w/ python. best regards, Nicolai
What the hell, people, there's an easy solution: Use GDC. - Gregor Richards
Not quite as easy as it might be. There seem to be far more pitfalls to getting a working shared library under D than under C. In addition, there is still no 2.0 support in GDC.
So long as the standard library is static instead of shared, it will always be more complicated. If the standard library was shared, this would be simple. Oh my god, there's STILL no 2.0 support in GDC after it's existed for almost TWO MONTHS??!?!?! For shame!!! Yeesh.
C'mon man, I didn't mean it like that. Of course there isn't a 2.0 release yet, and since it is a beta and very subject to change, I am not even sure that a GDC 2.0 release is a good idea yet. But if you have a project already using 2.0 features, you *aren't able* to switch to GDC to get shared library support.
 On a realated note, it would be nice to get libgphobos working as a 
 dynamic library with GDC, and shave a few 100K off of my executables...
http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmar .D&article_id=43626 - Gregor Richards
Cool, I will give this a try.
Aug 18 2007
prev sibling parent Jari-Matti =?ISO-8859-1?Q?M=E4kel=E4?= <jmjmak utu.fi.invalid> writes:
Tristam MacDonald wrote:

 On a realated note, it would be nice to get libgphobos working as a
 dynamic library with GDC, and shave a few 100K off of my executables...
If your 5 1/4" floppies are running out of space, there's an utility called sstrip and if it isn't enough, 'upx --ultra-brute foo.bin' might help too.
Aug 20 2007
prev sibling parent Nicolai Waniek <no.spam thank.you.com> writes:
Gregor Richards wrote:
 
 What the hell, people, there's an easy solution: Use GDC.
 
  - Gregor Richards
The main reason for this is, that I yet want to use 2.0 features... well I'll just wait a few weeks until GDC has those, but until then, I'll stick to another project ;) -- .71 nicolai dot waniek at sphere71 dot com
Aug 17 2007
prev sibling parent reply Gregor Richards <Richards codu.org> writes:
Steve Teale wrote:
 I've seen it said that dmd does not support creation of Linux shared
libraries, but I've also seen it said that you can use dmd -c to create a .o
file, and then use gcc -shared ... to create an so. Can anyone clarify the
position here please?
 
It is possible to create a .so file with DMD. It might even occasionally work. But not reliably. It's not exactly an easy process to get one working on GDC either, but it can work. DSSS automates the whole process :) - Gregor Richards
Aug 16 2007
parent reply Daniel Truemper <daniel-truemper gmx.de> writes:
Hi,

Gregor Richards wrote:
 It's not exactly an easy process to get one working on GDC either, but 
 it can work. DSSS automates the whole process :)
Can you give an example for creating a shared library on linux with DSSS? I read all readme's from DSSS but can't find it?! I am propably reading over it... Daniel -- "All work but no play makes Jack a dull boy"
Aug 16 2007
next sibling parent reply Daniel Truemper <daniel-truemper gmx.de> writes:
Daniel Truemper wrote:
 Can you give an example for creating a shared library on linux with
 DSSS? I read all readme's from DSSS but can't find it?! I am propably
 reading over it...
Ups, found it in the new README.software_engineers cheers, Daniel -- "All work but no play makes Jack a dull boy"
Aug 16 2007
parent reply Gregor Richards <Richards codu.org> writes:
Daniel Truemper wrote:
 Daniel Truemper wrote:
 Can you give an example for creating a shared library on linux with
 DSSS? I read all readme's from DSSS but can't find it?! I am propably
 reading over it...
Ups, found it in the new README.software_engineers cheers, Daniel
*snaps*, late by a minute ;) - Gregor Richards
Aug 16 2007
parent reply Daniel Truemper <daniel-truemper gmx.de> writes:
Gregor Richards wrote:
 *snaps*, late by a minute ;)
Thanks anyways! But I now have another question: I just built my library as a shared library, which is working; I'm getting all the so files and links. The I install the library (dsss install) and create a small test app that should include my library. When I build this app, I am getting a ld error: /usr/bin/ld: tmTest: hidden symbol `stat' in /usr/lib/libc_nonshared.a(stat.oS) is referenced by DSO /usr/bin/ld: final link failed: Nonrepresentable section on output collect2: ld returned 1 exit status Any idea what happend? cheers, Daniel -- "All work but no play makes Jack a dull boy"
Aug 17 2007
parent Daniel Truemper <daniel-truemper gmx.de> writes:
 I just built my library as a shared library, which is working; I'm
 getting all the so files and links. The I install the library (dsss
 install) and create a small test app that should include my library.
 When I build this app, I am getting a ld error:
 
 /usr/bin/ld: tmTest: hidden symbol `stat' in
 /usr/lib/libc_nonshared.a(stat.oS) is referenced by DSO
 /usr/bin/ld: final link failed: Nonrepresentable section on output
 collect2: ld returned 1 exit status
Just in case someone is getting the same or a similar error and is confused as I was. The problem is that your library propably requires another library and the you have to tell the linker to explicitly link the 3rd party library in yours. Do this by adding "-L-lc" to your build flags... cheers, Daniel -- "All work but no play makes Jack a dull boy"
Aug 19 2007
prev sibling parent Gregor Richards <Richards codu.org> writes:
Daniel Truemper wrote:
 Hi,
 
 Gregor Richards wrote:
 It's not exactly an easy process to get one working on GDC either, but 
 it can work. DSSS automates the whole process :)
Can you give an example for creating a shared library on linux with DSSS? I read all readme's from DSSS but can't find it?! I am propably reading over it... Daniel
From README.software_engineers line 155: When using GDC on GNU/Linux, it is also possible to build shared libraries (.so files). To specify that a shared library should be built, set the 'shared' option in the library's section: [mydpackage] shared You can set the .so file's version extension (the 1.2.3 in .so.1.2.3) with the soversion setting: [mydpackage] shared soversion=3.2.1 - Gregor Richards
Aug 16 2007