digitalmars.D.learn - problem with shared library and dlopen() function
- =?ISO-8859-2?Q?Micha=B3_Cie=B6lak?= (36/36) Aug 22 2007 Content-Disposition: inline
- Daniel Keep (8/12) Aug 24 2007 Last time I checked, DMD couldn't generate position-independent code on
- Witold Baryluk (6/10) Aug 24 2007 True. I was hardly trying but DMD can't do this.
- Frits van Bommel (5/18) Aug 25 2007 I think his point is that the issue is on Linux. There's a difference
Content-Disposition: inline At first I want to apologize for my English. I want to rewrite my Java program to D. I have problem with shared library and dlopen() function. calc_mean.d: extern(C){ double mean(double a, double b) { return (a+b) / 2; } } dmd -fPIC calc_mean.d -c gcc -shared -Wl,-soname,libmean.so.1 -o libmean.so.1.0.1 calc_mean.o -m32 test.d: import std.stdio; import std.c.linux.linux ; public void main(){ void *handle; double (*reff)(double, double); handle = dlopen("./libmean.so.1.0.1", RTLD_NOW); char *errstr = dlerror(); if(errstr != null) printf ("A dynamic linking error occurred: (%s)\n", errstr); *cast(void **)(&reff) = dlsym(handle, "mean"); errstr = dlerror(); if(errstr != null) printf ("A dynamic linking error occurred: (%s)\n", errstr); writefln((*reff)(1,12)); } dmd test -L-ldl ./test : ./test A dynamic linking error occurred: (./libmean.so.1.0.1: undefined symbol: _Dmodule_ref) A dynamic linking error occurred: (./test: undefined symbol: mean) Segmentation fault I am 17, so I am novice programmer. I don't know what I am doing wrong. Please help me.
Aug 22 2007
Michał Cieślak wrote:At first I want to apologize for my English. I want to rewrite my Java program to D. I have problem with shared library and dlopen() function. [snip]Last time I checked, DMD couldn't generate position-independent code on linux, which means it can't compile shared libraries. You might have more luck with the GDC compiler, but since I don't use linux, that's just a guess. You might also want to have a look at DDL <http://www.dsource.org/projects/ddl/>. -- Daniel
Aug 24 2007
Dnia Fri, 24 Aug 2007 17:08:54 +1000 Daniel Keep <daniel.keep.lists gmail.com> napisa=B3/a:Last time I checked, DMD couldn't generate position-independent code on linux, which means it can't compile shared libraries.True. I was hardly trying but DMD can't do this.You might have more luck with the GDC compiler, but since I don't use linux, that's just a guess.GDC is also for Win32. --=20 Witold Baryluk, aleph0
Aug 24 2007
Witold Baryluk wrote:Dnia Fri, 24 Aug 2007 17:08:54 +1000 Daniel Keep <daniel.keep.lists gmail.com> napisał/a:I think his point is that the issue is on Linux. There's a difference between Linux .so libraries and Windows DLLs: the latter don't require position-independent code (IIRC they contain relocation info) and DMD/Windows can in fact create them.Last time I checked, DMD couldn't generate position-independent code on linux, which means it can't compile shared libraries.True. I was hardly trying but DMD can't do this.You might have more luck with the GDC compiler, but since I don't use linux, that's just a guess.GDC is also for Win32.
Aug 25 2007