Bug creation and email sending has been disabled, file new bugs at gcc.gnu.org/bugzilla
Bug 243 - D compilers are not ABI compatible
Summary: D compilers are not ABI compatible
Status: RESOLVED WONTFIX
Alias: None
Product: GDC
Classification: Unclassified
Component: gdc (show other bugs)
Version: development
Hardware: All All
: --- enhancement
Assignee: Iain Buclaw
URL:
Depends on:
Blocks:
 
Reported: 2016-10-03 12:28 CEST by Chalix
Modified: 2023-01-07 21:02 CET (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Chalix 2016-10-03 12:28:45 CEST
Hi,
I found some inconsistency to the dmd compiler. If I want to compile this simple program:


import std.stdio;
import gtk.Main; /* -I/usr/local/include/d/gtkd-3 */

void main(string[] args)
{
	// Prints "Hello World" string in console
	writeln("Hello World!");
	
	// Lets the user press <Return> before program returns
	stdin.readln();
	return;
}


I get an error using gdc, but not with dmd. The GtkD library must be installed, though. My .so files are at a default location, the header files are at a seperate location.

Now the output of both:

~$ dmd main.d -I/usr/local/include/d/gtkd-3 -L-lgtkd-3
~$ ./main
Hello World!


~$ gdc main.d -I/usr/local/include/d/gtkd-3 -lgtkd-3
~$ ./a.out 
Fatal Error while loading '/usr/lib/x86_64-linux-gnu/libphobos2.so.0.71':
	The module 'std.array' is already defined in './a.out'.


It is this line, which causes the error:
import gtk.Main; /* -I/usr/local/include/d/gtkd-3 */
If I delete this line, a.out does not throw an error. (But I cant use the GtkD library then...)



Some more information:


~$ gdc --version
gdc (Ubuntu 5.4.0-6ubuntu1~16.04.2) 5.4.0 20160609

~$ ld -v
GNU ld (GNU Binutils for Ubuntu) 2.26.1

~$ dmd -v
DMD64 D Compiler v2.071.1
Comment 1 Iain Buclaw 2016-10-03 14:07:39 CEST
(In reply to Chalix from comment #0)
> ~$ gdc main.d -I/usr/local/include/d/gtkd-3 -lgtkd-3
> ~$ ./a.out 
> Fatal Error while loading '/usr/lib/x86_64-linux-gnu/libphobos2.so.0.71':
> 	The module 'std.array' is already defined in './a.out'.
> 
> 

My guess would be that gtkd was built with dmd, because this is not the phobos library used by gdc.
Comment 2 Chalix 2016-10-03 16:08:58 CEST
Does this mean, I can't include libraries in my gdc project, which are complied with dmd, because they use different implementations of the same standard library?

Or did I do something wrong, so that I could fix this?

My solution for now is, not to use gdc... But this seems not very satisfying. My understanding of a compiler is, that I can use them independent of each other.
Comment 3 Iain Buclaw 2016-10-03 16:30:12 CEST
(In reply to Chalix from comment #2)
> Does this mean, I can't include libraries in my gdc project, which are
> complied with dmd, because they use different implementations of the same
> standard library?
> 
> Or did I do something wrong, so that I could fix this?
> 

Well, you'd need a version of gtkd library built with gdc, and another with dmd.

DMD's install script is aware of both dmd and gdc, and will install them in separate environments in very much the same way as python's virtualenv.

https://dlang.org/install.sh

If you need separation, this would be the best way to do it.  Rather than installing libraries and interface files in /usr/local.
Comment 4 Johannes Pfau 2016-10-03 17:30:51 CEST
> Does this mean, I can't include libraries in my gdc project, which are complied 
> with dmd, because they use different implementations of the same standard 
> library? [...] My understanding of a compiler is, that I can use them
> independent of each other.

Ideally that should be that case, but right now none of the compilers are ABI compatible. I hope we'll solve this problem at some point, but as long as the DMD developers are not interested in this topic it's unlikely the GDC team can solve this problem with our limited resources.
 
So for now you'll have to compile all your dependencies with the same compiler. DUB can automatically handle this, though it is more difficult when using gtkD as a shared library.
Comment 5 Johannes Pfau 2016-10-03 17:32:03 CEST
> Does this mean, I can't include libraries in my gdc project, which are complied 
> with dmd, because they use different implementations of the same standard 
> library? [...] My understanding of a compiler is, that I can use them
> independent of each other.

Ideally that should be that case, but right now none of the compilers are ABI compatible. I hope we'll solve this problem at some point, but as long as the DMD developers are not interested in this topic it's unlikely the GDC team can solve this problem with our limited resources.
 
So for now you'll have to compile all your dependencies with the same compiler. DUB can automatically handle this, though it is more difficult when using gtkD as a shared library.
Comment 6 Chalix 2016-10-03 17:51:22 CEST
(In reply to Johannes Pfau from comment #5)
> Ideally that should be that case, but right now none of the compilers are
> ABI compatible. I hope we'll solve this problem at some point

Thank you, Johannes, that was exactly what I wanted to know :)

Would be great, if you could get the compilers ABI compatible. This also makes it easier to detect compiler bugs, because you can test against another compiler with a different implementation easier.

Just keep up communication with the dmd team :)

For now, I can live with the two separate libraries. And for DUB, I don't understand the magic behind it, and it also didn't work the first time, so I like to link my projects the conventional way^^
Comment 7 Iain Buclaw 2020-05-17 16:10:52 CEST
This is not really a gdc bug, as we only ever use the system ABI, I would instead extend the invitation for ldc/dmd to compatible with gdc.

The other way around is not possible.