[Issue 5468] New: Linker fails to link libraries using phobos2 with C code
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Thu Jan 20 11:54:33 PST 2011
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 at puremagic.com
ReportedBy: pastas4 at gmail.com
--- Comment #0 from GreatEmerald <pastas4 at gmail.com> 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
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: -------
More information about the Digitalmars-d-bugs
mailing list