www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Linking Error (WS2_32.LIB)

reply Tobse <tobias.m onlinehome.de> writes:
Hey,
i wanted to write a basic cli chat to get familiar with d. So i looked up the
default library for sockets and found std.socket; There is a note that says
"compile with ws2_32.lib". When i simply run:

dmd main.d

it tells me:

OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
dist\client.obj(client)
 Error 42: Symbol Undefined _D3std6socket7Address8toStringMFZAya
dist\client.obj(client)
 Error 42: Symbol Undefined _D3std6socket7Address13addressFamilyMFZE3std6socket1
3AddressFamily
dist\client.obj(client)
 Error 42: Symbol Undefined _D3std6socket7Address7nameLenMFZi
dist\client.obj(client)
 Error 42: Symbol Undefined _D3std6socket7Address4nameMFZPS3std1c7windows7winsoc
k8sockaddr
--- errorlevel 4

So then i tried this:

dmd main.d -Llib ws2_32.lib

But i keep getting the exact same error plus

OPTLINK : Warning 9: Unknown Option : NOILIB

doing this:

dmd main.d
link client.obj -lib ws2_32.lib

Its the same again plus

OPTLINK : Warning 9: Unknown Option : LIB


Can somone please tell me how to link the compiled code correctly so that i
can run it? Or is this a bug?

Greets, Tobi
Nov 09 2011
next sibling parent reply "Nick Sabalausky" <a a.a> writes:
"Tobse" <tobias.m onlinehome.de> wrote in message 
news:j9efl3$2igk$1 digitalmars.com...
 Hey,
 i wanted to write a basic cli chat to get familiar with d. So i looked up 
 the
 default library for sockets and found std.socket; There is a note that 
 says
 "compile with ws2_32.lib". When i simply run:

 dmd main.d

 it tells me:

 OPTLINK (R) for Win32  Release 8.00.12
 Copyright (C) Digital Mars 1989-2010  All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 dist\client.obj(client)
 Error 42: Symbol Undefined _D3std6socket7Address8toStringMFZAya
 dist\client.obj(client)
 Error 42: Symbol Undefined 
 _D3std6socket7Address13addressFamilyMFZE3std6socket1
 3AddressFamily
 dist\client.obj(client)
 Error 42: Symbol Undefined _D3std6socket7Address7nameLenMFZi
 dist\client.obj(client)
 Error 42: Symbol Undefined 
 _D3std6socket7Address4nameMFZPS3std1c7windows7winsoc
 k8sockaddr
 --- errorlevel 4

 So then i tried this:

 dmd main.d -Llib ws2_32.lib

 But i keep getting the exact same error plus

 OPTLINK : Warning 9: Unknown Option : NOILIB

 doing this:

 dmd main.d
 link client.obj -lib ws2_32.lib

 Its the same again plus

 OPTLINK : Warning 9: Unknown Option : LIB


 Can somone please tell me how to link the compiled code correctly so that 
 i
 can run it? Or is this a bug?

 Greets, Tobi

Not sure whether or not there's some other problem, but try this: dmd main.d ws2_32.lib
Nov 09 2011
parent reply Tobse <tobias.m onlinehome.de> writes:
No, did not work, same result.

C:\Users\Tobse\Documents\chat>dmd main.d ws2_32.lib -ofdist\client.exe
OPTLINK (R) for Win32  Release 8.00.12
Copyright (C) Digital Mars 1989-2010  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
dist\client.obj(client)
 Error 42: Symbol Undefined _D3std6socket7Address8toStringMFZAya
dist\client.obj(client)
 Error 42: Symbol Undefined _D3std6socket7Address13addressFamilyMFZE3std6socket1
3AddressFamily
dist\client.obj(client)
 Error 42: Symbol Undefined _D3std6socket7Address7nameLenMFZi
dist\client.obj(client)
 Error 42: Symbol Undefined _D3std6socket7Address4nameMFZPS3std1c7windows7winsoc
k8sockaddr
--- errorlevel 4
Nov 09 2011
parent mta`chrono <chrono mta-international.net> writes:
After compiling the sources dmd will call optlink to do the linking. I
don't know why it's failing, but try to pass -v to dmd to see what's
happening.

Once you're done, you'll see how it calls optlink which is documented
here: http://www.digitalmars.com/ctg/optlink.html

Command line operation of OPTLINK uses the following syntax:
LINK obj[,out[,map[,lib[,def[,res]]]]]

Please also have a look at the environment variables (See link). Optlink
will use them as search pathes. But it's also explanied there.

I'm not quite sure, because I'm living in the linux world. But maybe you
could also use the mingw tools to link ???

- mta`chrono
Nov 09 2011
prev sibling next sibling parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Wed, 09 Nov 2011 20:09:39 +0200, Tobse <tobias.m onlinehome.de> wrote:

 Hey,
 i wanted to write a basic cli chat to get familiar with d. So i looked  
 up the
 default library for sockets and found std.socket; There is a note that  
 says
 "compile with ws2_32.lib". When i simply run:

 dmd main.d

 it tells me:

 OPTLINK (R) for Win32  Release 8.00.12
 Copyright (C) Digital Mars 1989-2010  All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 dist\client.obj(client)
  Error 42: Symbol Undefined _D3std6socket7Address8toStringMFZAya
 dist\client.obj(client)
  Error 42: Symbol Undefined  
 _D3std6socket7Address13addressFamilyMFZE3std6socket1
 3AddressFamily
 dist\client.obj(client)
  Error 42: Symbol Undefined _D3std6socket7Address7nameLenMFZi
 dist\client.obj(client)
  Error 42: Symbol Undefined  
 _D3std6socket7Address4nameMFZPS3std1c7windows7winsoc
 k8sockaddr
 --- errorlevel 4

These errors don't have anything to do with ws2_32.lib. It looks like you are trying to use the latest version of std.socket sources (from git) with an outdated phobos.lib. Did you download the latest version of std.socket without rebuilding Phobos, or something? -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Nov 09 2011
parent reply "Tobias M." <tobias.m onlinehome.de> writes:
Am 10.11.2011 02:32, schrieb Vladimir Panteleev:
 On Wed, 09 Nov 2011 20:09:39 +0200, Tobse <tobias.m onlinehome.de> wrote:

 Hey,
 i wanted to write a basic cli chat to get familiar with d. So i looked
 up the
 default library for sockets and found std.socket; There is a note that
 says
 "compile with ws2_32.lib". When i simply run:

 dmd main.d

 it tells me:

 OPTLINK (R) for Win32 Release 8.00.12
 Copyright (C) Digital Mars 1989-2010 All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 dist\client.obj(client)
 Error 42: Symbol Undefined _D3std6socket7Address8toStringMFZAya
 dist\client.obj(client)
 Error 42: Symbol Undefined
 _D3std6socket7Address13addressFamilyMFZE3std6socket1
 3AddressFamily
 dist\client.obj(client)
 Error 42: Symbol Undefined _D3std6socket7Address7nameLenMFZi
 dist\client.obj(client)
 Error 42: Symbol Undefined
 _D3std6socket7Address4nameMFZPS3std1c7windows7winsoc
 k8sockaddr
 --- errorlevel 4

These errors don't have anything to do with ws2_32.lib. It looks like you are trying to use the latest version of std.socket sources (from git) with an outdated phobos.lib. Did you download the latest version of std.socket without rebuilding Phobos, or something?

Well, i should have the latest version because i started learning D this monday and downloaded the compiler on thuesday. I will try that -v option and maybe mingw works for me. I will also try this pgrama(lib, "ws2_32.lib");
Nov 10 2011
parent reply mta`chrono <chrono mta-international.net> writes:
Did you try to compile tango and druntime on your own or was that a
precompiled package that you've downloaded? Normally make clean and
rebuild helps in that case. You could dig the sources of phobos and look
if std.socket containts the symbols and then compare them with the
symbols of phobos.lib. But unfortunally this is a more advanced task.

can you tell me what you've actually downloaded? I've a windows xp
virtual maschine here and I'd like to replicate your issue.
Nov 10 2011
parent reply "Tobias M." <tobias.m onlinehome.de> writes:
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Am 10.11.2011 19:21, schrieb mta`chrono:
 Did you try to compile tango and druntime on your own or was that a
 precompiled package that you've downloaded? Normally make clean and
 rebuild helps in that case. You could dig the sources of phobos and look
 if std.socket containts the symbols and then compare them with the
 symbols of phobos.lib. But unfortunally this is a more advanced task.

 can you tell me what you've actually downloaded? I've a windows xp
 virtual maschine here and I'd like to replicate your issue.

Ive not come that far with my code so ill attach it as rar. Ill now try to compile the sources on my own, maybe ill get the same error again and then we´ll know where the problem is ;).
Nov 10 2011
next sibling parent "Tobias M." <tobias.m onlinehome.de> writes:
Am 10.11.2011 22:31, schrieb Tobias M.:
 Am 10.11.2011 19:21, schrieb mta`chrono:
 Did you try to compile tango and druntime on your own or was that a
 precompiled package that you've downloaded? Normally make clean and
 rebuild helps in that case. You could dig the sources of phobos and look
 if std.socket containts the symbols and then compare them with the
 symbols of phobos.lib. But unfortunally this is a more advanced task.

 can you tell me what you've actually downloaded? I've a windows xp
 virtual maschine here and I'd like to replicate your issue.

Ive not come that far with my code so ill attach it as rar. Ill now try to compile the sources on my own, maybe ill get the same error again and then we´ll know where the problem is ;).

http://www.digitalmars.com/d/2.0/dmd-windows.html#compiling_dmd but i still get the same errors. But there was a warning in the output: Notice: As of Phobos 2.055, std.gregorian has been deprecated. It will be remove d in February 2012. Please use std.datetime instead. So i presume that this is phobos 2.055 and my compiler is 2.056. Might this be the problem?
Nov 10 2011
prev sibling parent reply mta`chrono <chrono mta-international.net> writes:
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit

Hello Tobias,

thanks for attaching your code. I think we're getting closer to the bug.
What is class LanAddress : Address { } used for? I don't understand it's
purpose. I've modified your code for the usage of TCP/IP. Note:
SocketType.RAW is for geeks only ;-).

Compile: dmd -m32 main.d ws2_32.lib
Usage: main.exe digitalmars.com

- mta`chrono
Nov 10 2011
parent "Tobias M." <tobias.m onlinehome.de> writes:
Am 10.11.2011 23:44, schrieb mta`chrono:
 Hello Tobias,

 thanks for attaching your code. I think we're getting closer to the bug.
 What is class LanAddress : Address { } used for? I don't understand it's
 purpose. I've modified your code for the usage of TCP/IP. Note:
 SocketType.RAW is for geeks only ;-).

 Compile: dmd -m32 main.d ws2_32.lib
 Usage: main.exe digitalmars.com

 - mta`chrono

only way to represent an IP that i found was the abstract class Address. And since you cant instantiate abstract classes, i had to extend and re-implement it. But well, then ill continue with that. Thanks for sovling my problem guys.
Nov 10 2011
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 11/9/2011 10:09 AM, Tobse wrote:
 Hey,
 i wanted to write a basic cli chat to get familiar with d. So i looked up the
 default library for sockets and found std.socket; There is a note that says
 "compile with ws2_32.lib". When i simply run:

 dmd main.d

 it tells me:

 OPTLINK (R) for Win32  Release 8.00.12
 Copyright (C) Digital Mars 1989-2010  All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 dist\client.obj(client)
   Error 42: Symbol Undefined _D3std6socket7Address8toStringMFZAya
 dist\client.obj(client)
   Error 42: Symbol Undefined
_D3std6socket7Address13addressFamilyMFZE3std6socket1
 3AddressFamily
 dist\client.obj(client)
   Error 42: Symbol Undefined _D3std6socket7Address7nameLenMFZi
 dist\client.obj(client)
   Error 42: Symbol Undefined
_D3std6socket7Address4nameMFZPS3std1c7windows7winsoc
 k8sockaddr
 --- errorlevel 4

To compile main.d and link with ws2_32.lib, dmd main.d ws2_32.lib will work. However, that is not the problem you're having. There's clearly a mismatch between the phobos.lib you're linking with and the std.socket being read by the compiler. One is out of date with the other. In other words, the undefined symbols reported by the linker appear in std.socket but do not appear in phobos.lib.
Nov 10 2011
next sibling parent reply mta`chrono <chrono mta-international.net> writes:
Am 10.11.2011 20:46, schrieb Walter Bright:
 On 11/9/2011 10:09 AM, Tobse wrote:
 OPTLINK (R) for Win32  Release 8.00.12
 Copyright (C) Digital Mars 1989-2010  All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 dist\client.obj(client)
   Error 42: Symbol Undefined _D3std6socket7Address8toStringMFZAya
 dist\client.obj(client)
   Error 42: Symbol Undefined
 _D3std6socket7Address13addressFamilyMFZE3std6socket1
 3AddressFamily
 dist\client.obj(client)
   Error 42: Symbol Undefined _D3std6socket7Address7nameLenMFZi
 dist\client.obj(client)
   Error 42: Symbol Undefined
 _D3std6socket7Address4nameMFZPS3std1c7windows7winsoc
 k8sockaddr
 --- errorlevel 4

To compile main.d and link with ws2_32.lib, dmd main.d ws2_32.lib will work. However, that is not the problem you're having. There's clearly a mismatch between the phobos.lib you're linking with and the std.socket being read by the compiler. One is out of date with the other. In other words, the undefined symbols reported by the linker appear in std.socket but do not appear in phobos.lib.

Walter, have you looked into his source. What he did was: --------- BEGIN ---------- import std.socket; class FoobarAddress : Address { } void main() { } ---------- END --------- compile this with dmd -m32 main.d and you'll see exactly the same errors that he posted. Even tough dmd's error message are a little bit confusing in this case, the problem should be clear. - mta`chrono
Nov 10 2011
parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 11/10/2011 2:50 PM, mta`chrono wrote:
 Walter, have you looked into his source. What he did was:

 --------- BEGIN ----------
 import std.socket;

 class FoobarAddress : Address
 {

 }

 void main()
 {

 }
 ---------- END ---------

 compile this with dmd -m32 main.d and you'll see exactly the same errors
 that he posted. Even tough dmd's error message are a little bit
 confusing in this case, the problem should be clear.

You're right. And the problem is that Address is an *abstract* class, defined as: abstract class Address { protected sockaddr* name(); protected int nameLen(); AddressFamily addressFamily(); override string toString(); } This means that anyone deriving from it needs to implement those functions.
Nov 10 2011
parent reply "Nick Sabalausky" <a a.a> writes:
"Walter Bright" <newshound2 digitalmars.com> wrote in message 
news:j9hp3g$aqd$1 digitalmars.com...
 On 11/10/2011 2:50 PM, mta`chrono wrote:
 Walter, have you looked into his source. What he did was:

 --------- BEGIN ----------
 import std.socket;

 class FoobarAddress : Address
 {

 }

 void main()
 {

 }
 ---------- END ---------

 compile this with dmd -m32 main.d and you'll see exactly the same errors
 that he posted. Even tough dmd's error message are a little bit
 confusing in this case, the problem should be clear.

You're right. And the problem is that Address is an *abstract* class, defined as: abstract class Address { protected sockaddr* name(); protected int nameLen(); AddressFamily addressFamily(); override string toString(); } This means that anyone deriving from it needs to implement those functions.

Isn't this a bug that the compiler accepted it and the error didn't get raised until it got all the way to the linker? Doesn't the compiler normally catch that before it gets to the linker?
Nov 10 2011
next sibling parent bearophile < bearophileHUGS lycos.com> writes:
Nick Sabalausky:

 Isn't this a bug that the compiler accepted it and the error didn't get 
 raised until it got all the way to the linker?

Of course. Bye, bearophile
Nov 10 2011
prev sibling parent reply Walter Bright <newshound2 digitalmars.com> writes:
On 11/10/2011 5:10 PM, Nick Sabalausky wrote:
 Isn't this a bug that the compiler accepted it and the error didn't get
 raised until it got all the way to the linker? Doesn't the compiler normally
 catch that before it gets to the linker?

No. The reason is the implementation may be in another .obj file known only to the linker.
Nov 10 2011
next sibling parent "Nick Sabalausky" <a a.a> writes:
"Walter Bright" <newshound2 digitalmars.com> wrote in message 
news:j9i0c5$mlb$1 digitalmars.com...
 On 11/10/2011 5:10 PM, Nick Sabalausky wrote:
 Isn't this a bug that the compiler accepted it and the error didn't get
 raised until it got all the way to the linker? Doesn't the compiler 
 normally
 catch that before it gets to the linker?

No. The reason is the implementation may be in another .obj file known only to the linker.

But even if it is, it should still at least be declared in the .d file that has the class's definition, shouldn't it?
Nov 11 2011
prev sibling parent "Tobias M." <tobias.m onlinehome.de> writes:
Am 11.11.2011 13:29, schrieb Vladimir Panteleev:
 On Fri, 11 Nov 2011 04:12:43 +0200, Walter Bright
 <newshound2 digitalmars.com> wrote:

 On 11/10/2011 5:10 PM, Nick Sabalausky wrote:
 Isn't this a bug that the compiler accepted it and the error didn't get
 raised until it got all the way to the linker? Doesn't the compiler
 normally
 catch that before it gets to the linker?

No. The reason is the implementation may be in another .obj file known only to the linker.

I can't see how that makes sense, even with the above (un-idiomatic?) idea. The compiler should not emit references to *abstract* methods. I think this looks like a case of class attributes not affecting methods: "Address" is declared as an abstract class, but the compiler doesn't realize that its methods are abstract too. They are simply declared as method declarations without a body. This is similar to another old bug (now fixed, I believe), when methods of "final" classes were still implicitly virtual.

methods from Address then? Ok, so if thats the point im fine with it. I just thought (as it is in Java and PHP), that methods in abstract classes need to have a body too. If an extending class isn´t implementing those, theyll simply get copied.
Nov 11 2011
prev sibling parent "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Fri, 11 Nov 2011 04:12:43 +0200, Walter Bright  
<newshound2 digitalmars.com> wrote:

 On 11/10/2011 5:10 PM, Nick Sabalausky wrote:
 Isn't this a bug that the compiler accepted it and the error didn't get
 raised until it got all the way to the linker? Doesn't the compiler  
 normally
 catch that before it gets to the linker?

No. The reason is the implementation may be in another .obj file known only to the linker.

I can't see how that makes sense, even with the above (un-idiomatic?) idea. The compiler should not emit references to *abstract* methods. I think this looks like a case of class attributes not affecting methods: "Address" is declared as an abstract class, but the compiler doesn't realize that its methods are abstract too. They are simply declared as method declarations without a body. This is similar to another old bug (now fixed, I believe), when methods of "final" classes were still implicitly virtual. -- Best regards, Vladimir mailto:vladimir thecybershadow.net
Nov 11 2011