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: nob...@puremagic.com
        ReportedBy: timo.westkam...@gmail.com


--- Comment #0 from Timo Westk´┐Żmper <timo.westkam...@gmail.com> 2012-04-09 
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
#!/bin/bash
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: -------

Reply via email to