Summary: Linker fails to link libraries using phobos2 with C
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Optlink

--- Comment #0 from GreatEmerald <> 2011-01-20 11:52:33 PST ---
When you try to create a static D library that imports and/or uses anything
from the phobos2 library, the generated library can no longer be linked with C

For testing purposes, I have two files, the D library:
module dpart;
import std.stdio;

shared int ResultD;

int Process(int Value)
    printf("You have sent the value %d to the D library.\n", Value);
    ResultD = (Value % 5);
    return ResultD;
And the C file that is using the library:
#include <stdio.h>

extern int ResultD;

int Process(int Value);

int main()
    int Result;

    printf("This text is written in C. Input a number.\n");
    scanf("%d", &Result);
    printf("%d modulus 5 is %d.\n", Result, ResultD);
    return 0;
I compile this code using two steps:
dmd -c -lib dpart.d
dmc dpart.lib cpart.c

And I get this linker error:
link cpart,,,dpart+user32+kernel32/noi;
OPTLINK (R) for Win32  Release 8.00.5
Copyright (C) Digital Mars 1989-2009  All rights reserved.
 Warning 140: Library probably needs FIXLIB
 Error 42: Symbol Undefined _D3std5stdio12__ModuleInfoZ

--- errorlevel 1
I get additional errors if I try to use writeln() instead of printf(), but it
compiles and runs fine if I import std.c.stdio instead of std.stdio. Linking
also fails if I try to import any of other parts of phobos2 included in D, such
as std.path.

I'm using DMD 2.051 and DMC 8.42n on Windows 7 x64.

Configure issuemail:
------- You are receiving this mail because: -------

Reply via email to