Bug 17851 – htonl already defined in phobos64.lib

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P1
Component
druntime
Product
D
Version
D2
Platform
x86_64
OS
Windows
Creation time
2017-09-23T03:11:05Z
Last change time
2017-12-18T22:54:27Z
Assigned to
No Owner
Creator
Heromyth

Comments

Comment #0 by bitworld — 2017-09-23T03:11:05Z
When building a simple demo for libevent(https://github.com/D-Programming-Deimos/libevent) on Windows 10 X64, I got these errors blown: ws2_32.lib(WS2_32.dll) : error LNK2005: htonl already defined in phobos64.lib(winsock2_1f3b_225.obj) ws2_32.lib(WS2_32.dll) : error LNK2005: htons already defined in phobos64.lib(winsock2_1f3a_22c.obj) ws2_32.lib(WS2_32.dll) : error LNK2005: ntohl already defined in phobos64.lib(winsock2_1f3d_225.obj) ws2_32.lib(WS2_32.dll) : error LNK2005: ntohs already defined in phobos64.lib(winsock2_1f3c_22c.obj) I redefined these functions in druntime\src\core\sys\windows\winsock2.d. For example: uint htonl(uint x) { return bswap(x); } is changed to: uint htonl(uint x); After rebuilding the phobos64.lib, I can eliminate these errors. Here is a test code: import std.stdio; import deimos.event2.event; import std.socket; void main() { event_base_loopbreak(null); InternetAddress addr1 = new InternetAddress("127.0.0.1", 80); writeln(addr1.port); writeln(addr1.addr); } Compiler: dmd v2.076.0/VC++ 2017 OS: Windows 10 x64
Comment #1 by bitworld — 2017-09-23T03:18:43Z
It seems these functions have been defined in Ws2_32.lib, see https://msdn.microsoft.com/en-us/library/windows/desktop/ms738556(v=vs.85).aspx
Comment #2 by github-bugzilla — 2017-10-30T19:43:07Z
Commit pushed to master at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/cf8ed256f956f1fb551c314881922b8fc817246b core.sys.windows.winsock2: Don't implement htons() etc. To prevent duplicate symbols when pulling in that object file and the implementations in the ws2_32 library during linking. fix issue 17851 and https://github.com/ldc-developers/ldc/issues/468
Comment #3 by github-bugzilla — 2017-12-18T22:54:27Z
Commit pushed to stable at https://github.com/dlang/druntime https://github.com/dlang/druntime/commit/cf8ed256f956f1fb551c314881922b8fc817246b core.sys.windows.winsock2: Don't implement htons() etc.