www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 5468] New: Linker fails to link libraries using phobos2 with C code

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

           Summary: Linker fails to link libraries using phobos2 with C
                    code
           Product: D
           Version: D2
          Platform: x86_64
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Optlink
        AssignedTo: nobody puremagic.com
        ReportedBy: pastas4 gmail.com



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
programs.

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

extern(C):
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);
    Process(Result);
    printf("%d modulus 5 is %d.\n", Result, ResultD);
    getchar();
    getchar();
    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.
http://www.digitalmars.com/ctg/optlink.html
dpart.lib
 Warning 140: Library probably needs FIXLIB
dpart.lib(dpart)
 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: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jan 20 2011
parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=5468


Brad Roberts <braddr puremagic.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |braddr puremagic.com
         Resolution|                            |INVALID



---
You need to link against the phobos library as well, something like:

dmd -c -lib dpart.d
dmc cpart.c dpart.lib phobos.lib


Alternatively, use dmd for the last step, something like:

dmd -c -lib dpart.d
dmc -c cpart.c
dmd cpart.o dpart.lib

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Feb 06 2011