www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Bug in OPTLINK?

reply WeirdCat <sorry i.hate.spam> writes:
Hi,

i found a strange bug if i compile this (use make):
http://www.fastshare.org/download/test.rar

OPTLINK thinks the Symbol _WSAGetLastError 0 is undefined. It seams, that it
forgets to include "Ws2_32.lib", but if i uncomment line 3 *or* 6 in test.d,
everything works finde?!?

Is this realy a bug in the linker or do i miss something here?

LLAP,
Sascha
Jun 13 2007
parent reply Myron Alexander <someone somewhere.com> writes:
WeirdCat wrote:
 Hi,
 
 i found a strange bug if i compile this (use make):
 http://www.fastshare.org/download/test.rar
 
 OPTLINK thinks the Symbol _WSAGetLastError 0 is undefined. It seams, that it
forgets to include "Ws2_32.lib", but if i uncomment line 3 *or* 6 in test.d,
everything works finde?!?
 
 Is this realy a bug in the linker or do i miss something here?
 
 LLAP,
 Sascha

I could not download the file. Fastshare would not give it to me and I do not read the language so I don't know why. It's 1.79KB, just attach it to your posting. Regards, Myron.
Jun 13 2007
parent reply WeirdCat <sorry i.hate.spam> writes:
Content-Type: text/plain

Myron Alexander Wrote:
 It's 1.79KB, just attach it to your posting.

I wasn't sure if this newsgroup accepts attachments... LLAP, Sascha
Jun 13 2007
parent reply David L. Davis <SpottedTiger yahoo.com> writes:
WeirdCat,

   I did the follwing below and it compiles fine with dmd v1.015 on WinXP SP2
(32-bit)...so I don't think it's the linker.

Install as follows:
-------------------
C:\dmd\test
   testme.d (renamed from test.d to testme.d)
        |->Lib
           win32.lib
        |->Win32
           winsock2.d

Note: Windows' environment variable "Path" has the below added
set path=%path%;C:\dm\bin;c:\dm\include;c:\dm\lib;C:\dmd\bin;C:\dmd;
           
Windows' Commanline (cmd.exe running in C:\dmd\test):  
-----------
dmd testme.d win32\winsock2.d ws2_32.lib (compiles, with no errors)
dmd testme.d win32\winsock2.d (compiles, with no errors)
         
Code:
-----
//--- testme.d ---
module testme; // added
private import win32.winsock2; // changed some

pragma(lib, "Ws2_32.lib"); // line 3 - uncommented

int main(char[][] args) 
{
	WSADATA wd;	   // line 6 - uncommented
	WSAGetLastError();
	return 0;
}         

//--- winsock2.d ---
module win32.winsock2;
pragma(lib, "Ws2_32.lib");

alias ushort WORD;

const size_t
	WSADESCRIPTION_LEN = 256,
	WSASYS_STATUS_LEN  = 128;

struct WSADATA 
{
	WORD   wVersion;
	WORD   wHighVersion;
	char[WSADESCRIPTION_LEN+1] szDescription;
	char[WSASYS_STATUS_LEN+1]  szSystemStatus;
	ushort iMaxSockets;
	ushort iMaxUdpDg;
	char*  lpVendorInfo;
}

extern(Windows) int WSAGetLastError();

David L.
Jun 13 2007
parent reply WeirdCat <sorry i.hate.spam> writes:
David L. Davis Wrote:
    I did the follwing below and it compiles fine with dmd v1.015 on WinXP SP2
(32-bit)...so I don't think it's the linker.

Try it without uncommenting the 2 lines and with the command: dmd test.d lib\win32.lib Result: test.obj(test) Error 42: Symbol Undefined _WSAGetLastError 0 test.d includes win32.winsock2 and the "pragma(lib, "Ws2_32.lib");" in winsock2.d should tell the linker to include Ws2_32.lib, but it doesn't (only exception from that is if you uncomment line 6 in test.d). If you manualy include Ws2_32.lib a) via command line "dmd test.d lib\win32.lib Ws2_32.lib" or b) via uncommenting "pragma(lib, "Ws2_32.lib");" (line 3) it works. But you shouldn't have to do it. Therefore I think there is a subtle bug in the linker. LLAP, Sascha
Jun 13 2007
parent reply David L. Davis <SpottedTiger yahoo.com> writes:
WeirdCat,

    I commented in the "pragma(lib, "Ws2_32.lib");" line in testme.d, but left
it in C:\dmd\test\win32\winsock2.d...and then just added the win32\winsock2.d
parameter to the commandline (dmd testme.d win32\winsock2.d). It still compiles
in my tests...maybe the linker's path is missing in your environment "Path"
variable.

David L.

WeirdCat Wrote:

 David L. Davis Wrote:
    I did the follwing below and it compiles fine with dmd v1.015 on WinXP SP2
(32-bit)...so I don't think it's the linker.

Try it without uncommenting the 2 lines and with the command: dmd test.d lib\win32.lib Result: test.obj(test) Error 42: Symbol Undefined _WSAGetLastError 0 test.d includes win32.winsock2 and the "pragma(lib, "Ws2_32.lib");" in winsock2.d should tell the linker to include Ws2_32.lib, but it doesn't (only exception from that is if you uncomment line 6 in test.d). If you manualy include Ws2_32.lib a) via command line "dmd test.d lib\win32.lib Ws2_32.lib" or b) via uncommenting "pragma(lib, "Ws2_32.lib");" (line 3) it works. But you shouldn't have to do it. Therefore I think there is a subtle bug in the linker. LLAP, Sascha

Jun 13 2007
parent reply WeirdCat <sorry i.hate.spam> writes:
David L. Davis Wrote:
     I commented in the "pragma(lib, "Ws2_32.lib");" line in testme.d, but left
it in C:\dmd\test\win32\winsock2.d...and then just added the win32\winsock2.d
parameter to the commandline (dmd testme.d win32\winsock2.d). It still compiles
in my tests...maybe the linker's path is missing in your environment "Path"
variable.

I know that it works if you use that command line. The Problem only manifests if you link with the library (.lib), which you don't do (try: "dmd test.d lib\win32.lib". The original win32 project has _much_ more files (http://www.dsource.org/projects/bindings/browser/trunk/win32), why it is impractical to list every source file on the command line or compile it every time I rebuild the project. That's why I have to precompile the win32 directory into a library, so I can easily link it. LLAP, Sascha
Jun 13 2007
parent David L. Davis <SpottedTiger yahoo.com> writes:
Sascha,

    Your link that you gave, gives me an error...but either way...I'd still
like to suggest that you look into a couple of D building tools that are on the
D Source web-site.

    Tool for building D executables and libraries
    -------------------------------------------------------------
    Bud: http://www.dsource.org/projects/build
    DSSS: http://www.dsource.org/projects/dsss

   Sorry, I wasn't helpfully enough to solve your issue, but hopefully one or
both of the above tools will fix it.

David L. Davis

WeirdCat Wrote:

 David L. Davis Wrote:
     I commented in the "pragma(lib, "Ws2_32.lib");" line in testme.d, but left
it in C:\dmd\test\win32\winsock2.d...and then just added the win32\winsock2.d
parameter to the commandline (dmd testme.d win32\winsock2.d). It still compiles
in my tests...maybe the linker's path is missing in your environment "Path"
variable.

I know that it works if you use that command line. The Problem only manifests if you link with the library (.lib), which you don't do (try: "dmd test.d lib\win32.lib". The original win32 project has _much_ more files (http://www.dsource.org/projects/bindings/browser/trunk/win32), why it is impractical to list every source file on the command line or compile it every time I rebuild the project. That's why I have to precompile the win32 directory into a library, so I can easily link it. LLAP, Sascha

Jun 14 2007