www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 7870] New: Shared library support for Linux is missing

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7870

           Summary: Shared library support for Linux is missing
           Product: D
           Version: unspecified
          Platform: x86
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: nobody puremagic.com
        ReportedBy: timo.westkamper gmail.com



00:00:21 PDT ---
Shared library creation for Linux via dmd doesn't work.

Here is my latest test:

* test.d:
import std.stdio;
extern (C) {
  void hiD() {
    writeln("hi from D lib");
  }
}

* main.c
#include <stdio.h>
#include <dlfcn.h>
#include <stdlib.h>
void main() {
    void (*hiD)(void);
    void* handle = dlopen("./libtest.so", RTLD_LAZY);
    if (handle == NULL) {
        printf("%s\n", dlerror());
        exit(1);
    }    
    hiD = dlsym(handle, "hiD");
    if (hiD != NULL) {
        hiD();
    } else {
        printf("hiD is null\n");
    }
    dlclose(handle);
}

* Makefile

test:
    #gdc-4.6 -g -c test.d -fPIC -o test.o
    #gdc-4.6 -shared -o libtest.so -fPIC test.o -lc -nostartfiles
    dmd -g -c test.d -fPIC
    ld -shared -o libtest.so test.o -lrt -lphobos2 -lpthread
    gcc -g main.c -ldl -lpthread
    ./a.out
clean:
    rm -rf *.so *.o *.out

With this setup I get

  ./libtest.so: undefined symbol: _deh_beg

With a fake main method added I get

  make: *** [test] Segmentation fault

This is what I get from gdb

  Program received signal SIGSEGV, Segmentation fault.
  0xb7fd1ed3 in std.stdio.__T7writelnTAyaZ.writeln() 
(_param_0=...) at   /usr/include/d/dmd/phobos/std/stdio.d:1550
  1550        enforce(fprintf(.stdout.p.handle, "%.*s\n",

I am using dmd 2.058 on Ubuntu 11.10 (32 bit)

With gdc I get different errors, but it seems even more difficult 
to get it working.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 08 2012
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=7870




08:30:56 PDT ---
Here is a related post :
http://forum.dlang.org/thread/cbpabrtlpnjtdtkijihq forum.dlang.org

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 14 2012