February 28, 2014
On Friday, 28 February 2014 at 17:29:09 UTC, Setra wrote:
> I am using  dmd_2.065.0-0_i386.deb on a 32 bit machine.

Hi Setra,

I am trying to make external libraries work as well, but having problems continuously. Could you test that following function in your library and call it from main programme. I am having "Segmentation Fault" with it, and wondering if other people has the same thing.

class A{
	public this(){
		writeln("Created");
	}
}

extern(C) void foo(){
	Object obj = new Object();

	A objA = new A();

	char[] c = new char[ 1024 ];
}
February 28, 2014
On Friday, 28 February 2014 at 17:29:09 UTC, Setra wrote:
> I am using  dmd_2.065.0-0_i386.deb on a 32 bit machine.

Ah, I can reproduce it with 32bit executables:

# dmd -m32 main1.d -L-ldl
# dmd -m32 -c dll.d -fPIC
# dmd -m32 -oflibdll.so dll.o -shared -defaultlib=
# LD_LIBRARY_PATH=. ./main1
+main()
libdll.so is loaded
dll() function is found
dll()
134684056
unloading libdll.so
-main()
# file ./main1
./main1: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, BuildID[sha1]=a0eb9b8af3a95d0c4fddd2daf7a476aabed4b53e, not stripped

Might be a compiler bug...
February 28, 2014
On Friday, 28 February 2014 at 18:05:13 UTC, Marc Schütz wrote:
> On Friday, 28 February 2014 at 17:29:09 UTC, Setra wrote:
>> I am using  dmd_2.065.0-0_i386.deb on a 32 bit machine.
>
> Ah, I can reproduce it with 32bit executables:
>
> # dmd -m32 main1.d -L-ldl
> # dmd -m32 -c dll.d -fPIC
> # dmd -m32 -oflibdll.so dll.o -shared -defaultlib=
> # LD_LIBRARY_PATH=. ./main1
> +main()
> libdll.so is loaded
> dll() function is found
> dll()
> 134684056
> unloading libdll.so
> -main()
> # file ./main1
> ./main1: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.16, BuildID[sha1]=a0eb9b8af3a95d0c4fddd2daf7a476aabed4b53e, not stripped
>
> Might be a compiler bug...

No, it isn't. The problem is here:
int function(int x) fn = cast(int function(int x))dlsym(lh, "dll");

This should be:
extern(C) int function(int x) fn = cast(int function(int x))dlsym(lh, "dll");

The calling conventions for C and D are different on x86, but happen to agree on x86_64 (at least the parts that are relevant here).

Btw, the forward declaration on top "extern (C) int dll();" isn't used anywhere.
February 28, 2014
Thanks! That was perfect!
1 2
Next ›   Last »