Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Ticket #1853 (new defect)

Opened 14 years ago

Last modified 14 years ago

Cannot build Win32 applications

Reported by: Michal Minich Assigned to: community
Priority: major Milestone: 1.0
Component: Tango Version: 0.99.9 Kai
Keywords: Cc:

Description

I was using DMDwith about month-two old snapshot. After upgrading to 0.99.9 my application stopped to build. It is very strange, that only when the "foreach" statement is included, I get following error:

OPTLINK : Warning 183: Extension not .RES : tango.lib C:\Soft\D\tango\bin\..\lib\tango.lib(dmain2)

Error 42: Symbol Undefined Dmain

test code:

file "main.d": module main;

extern (C) {

void gc_init (); void gc_term (); void _minit (); void _moduleCtor (); void _moduleDtor ();

}

extern (Windows) int WinMain? ( void* hInstance, void* hPrevInstance, char* lpCmdLine, int nCmdShow) {

gc_init (); _minit ();

try {

_moduleCtor ();

_moduleDtor ();

foreach (ch; "abc") {} // This line causes error.

} catch (Object o) { }

gc_term ();

return 1;

}

I used the following def file "main.def":
EXETYPE NT
SUBSYSTEM WINDOWS

and command line:
dmd main.d main.def

This exact code compiles under DMD+Phobos 1.056

This is for me critical problem, because I cannot build any file / tango file that use foreach.

Change History

02/11/10 01:37:22 changed by h3r3tic

I've tried your example with DMD 1.051 and Tango rev. 5348 and got a similar error message, albeit about snn.lib, not tango.lib. The trick to get it working was removing "-L+snn.lib" from my sc.ini. Having -L+tango.lib there causes the warning you're getting, but it works just fine if my sc.ini looks like this:

[Environment]
LIB="%@P%\..\lib;%@P%\..\..\dm\lib"
DFLAGS="-I%@P%\..\import" "-I%@P%\..\import\tango\core\vendor" -version=Tango -defaultlib=tango
LINKCMD=%@P%\..\..\dm\bin\link.exe

Perhaps it works for you with Phobos because you don't use -L+phobos.lib with it but instead -defaultlib=phobos (or maybe it's set to phobos by default).

02/14/10 11:26:30 changed by larsivi

Michal, could you please try h3r3tic's solution?

02/14/10 23:17:36 changed by Michal Minich

sorry for late response, I was out of reach of computer.

removing "-L+tango.lib" from sc.ini changes something, but it is not solution.

with original sc.ini from tango bundle (with "-L+tango.lib") the executable file is build, but it is probably invalid, because when it is run, it prints out into console "Program too big to fit in memory". Also the map file is empty.

when "-L+tango.lib" is removed from sc.ini the resulting program shows a message box ".. is not a valid Win32 application." the map file show some content now.

when the foreach statement is commented out in the source file, seems that correct executable is built either way. only warning is printed during building with "-L+tango.lib" - "OPTLINK : Warning 183: Extension not .RES : tango.lib", but both ways, the generated obj map and exe are exactly the same.

using: DFLAGS="-I%@P%\..\import" "-I%@P%\..\import\tango\core\vendor" -version=Tango -defaultlib=tango

insetead of: DFLAGS="-I%@P%\..\import" "-I%@P%\..\import\tango\core\vendor" -version=Tango -defaultlib=tango.lib -debuglib=tango.lib

seems to have same effect.

03/28/10 13:22:07 changed by larsivi

  • priority changed from blocker to major.

Did you say which Windows version you were using? As far as I know, noone else has reported this.

03/28/10 21:38:20 changed by torhu

Using DMD 1.056, Tango 0.99.9, Windows 7.

The foreach issue might be a weird dmd bug. I got the same result you got. But this version works just fine, even though it contains foreach:

module main;

import tango.core.Runtime;

extern (C) int printf(char*, ...);

extern (Windows) int WinMain ( void* hInstance, void* hPrevInstance, char* lpCmdLine, int nCmdShow) {
    // just pretending that exceptions can't happen here
    Runtime.initialize();
    foreach (ch; "abc") { printf("%c\n", ch); }
    Runtime.terminate();

    return 1;
}

// dummy D main, to satisfy the linker (this is __Dmain)
void main() { printf("never gets here\n"); }

I changed the initialization code, since your version caused a crash in gc_term upon shutdown.

The real issue seems to be that you have to define a dummy a D main, even though it's not supposed to be needed. The equivalent Phobos 2.040 version of this code doesn't require a D main, even though the runtimes are structured more or less the same. Could be some change made during the reorganization of Tango before 0.99.9 that caused this.

Changing sc.ini doesn't seeme to make a difference for me, but just in case here's the last one I tried:

[Version]
version=7.51 Build 020

[Environment]
LIB="%@P%\..\lib;%@P%\..\..\dm\lib;%@P%\..\..\import\tango"
DFLAGS="-I%@P%\..\..\import\tango" "-I%@P%\..\..\import\tango\core\vendor" -version=Tango -defaultlib=tango
LINKCMD=%@P%\..\..\dm\bin\link.exe

It might be a good idea to check that you don't have any environment variables set that dmd or optlink might pick up, like LINK, LIB, DFLAGS, or LINKCMD. Maybe that could cause the other issues.

04/24/10 22:10:10 changed by kris

  • owner changed from kris to community.