www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - msgpack link failure - non-transitive pragma(lib)?

reply TED_996 <ted_996 gmail.com> writes:
I've been trying to debug this for a long time now. I am trying 
to build one of the msgpack examples (examples/upacker_foreach.d) 
and the linking failed. I have since succeeded and I'm trying to 
find out if this is intended behavior or a bug in D (not msgpack, 
I think).

TL;DR: it seems to me like the pragma(lib, "ws2_32"); in 
core.sys.windows.winsock2, imported in msgpack.common, imported 
in msgpack (package.d), imported in my source files, does not 
hold; this was fixed when I added the pragma in my source file 
too.

Versions: Windows 10, dmd 2.080.0, dub 1.9.0

The dub build output:

Performing "debug" build using D:\D\dmd2\windows\bin\dmd.exe for 
x86.
msgpack-d 1.0.0-beta.6: target for configuration "library" is up 
to date.
hw ~master: building configuration "application"...
Linking...

OPTLINK (R) for Win32  Release 8.00.17
Copyright (C) Digital Mars 1989-2013  All rights reserved.
http://www.digitalmars.com/ctg/optlink.html
.dub\build\application-debug-windows-x86-dmd_2080-1E3111031ACEC4AEF53C62127331208A\hw.obj(hw)
  Error 42: Symbol Undefined _ntohl 4
.dub\build\application-debug-windows-x86-dmd_2080-1E3111031ACEC4AEF53C62127331208A\hw.obj(hw)
  Error 42: Symbol Undefined _ntohs 4
Error: linker exited with status 2
D:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.

dub.json:

{
	"name": "hw",
	"authors": [
		"ted_996"
	],
	"description": "A minimal D application.",
	"copyright": "Copyright © 2018, ted_996",
	"license": "proprietary",
	"dependencies": {
		"msgpack-d": ">=1.0.0-beta.6"
	}
}

After some digging, I found that other binaries that used msgpack 
(DCD) were importing ws2_32, but it seemed like my binary was 
not. Both debug and release and x86 and x64 versions were failing 
to link; msgpack built fine but probably only the msgpack.lib 
file (no final link).

However, when I (counter-intuitively, for me) added pragma(lib, 
"ws2_32"); to my own source files, it built successfully. Should 
that have been necessary? it was not in any examples. What gives?

Thanks!
May 11 2018
parent reply Basile B. <b2.temp gmx.com> writes:
On Friday, 11 May 2018 at 12:35:52 UTC, TED_996 wrote:
 I've been trying to debug this for a long time now. I am trying 
 to build one of the msgpack examples 
 (examples/upacker_foreach.d) and the linking failed. I have 
 since succeeded and I'm trying to find out if this is intended 
 behavior or a bug in D (not msgpack, I think).

 TL;DR: it seems to me like the pragma(lib, "ws2_32"); in 
 core.sys.windows.winsock2, imported in msgpack.common, imported 
 in msgpack (package.d), imported in my source files, does not 
 hold; this was fixed when I added the pragma in my source file 
 too.

 Versions: Windows 10, dmd 2.080.0, dub 1.9.0

 The dub build output:

 Performing "debug" build using D:\D\dmd2\windows\bin\dmd.exe 
 for x86.
 msgpack-d 1.0.0-beta.6: target for configuration "library" is 
 up to date.
 hw ~master: building configuration "application"...
 Linking...

 OPTLINK (R) for Win32  Release 8.00.17
 Copyright (C) Digital Mars 1989-2013  All rights reserved.
 http://www.digitalmars.com/ctg/optlink.html
 .dub\build\application-debug-windows-x86-dmd_2080-1E3111031ACEC4AEF53C62127331208A\hw.obj(hw)
  Error 42: Symbol Undefined _ntohl 4
 .dub\build\application-debug-windows-x86-dmd_2080-1E3111031ACEC4AEF53C62127331208A\hw.obj(hw)
  Error 42: Symbol Undefined _ntohs 4
 Error: linker exited with status 2
 D:\D\dmd2\windows\bin\dmd.exe failed with exit code 1.

 dub.json:

 {
 	"name": "hw",
 	"authors": [
 		"ted_996"
 	],
 	"description": "A minimal D application.",
 	"copyright": "Copyright © 2018, ted_996",
 	"license": "proprietary",
 	"dependencies": {
 		"msgpack-d": ">=1.0.0-beta.6"
 	}
 }

 After some digging, I found that other binaries that used 
 msgpack (DCD) were importing ws2_32, but it seemed like my 
 binary was not. Both debug and release and x86 and x64 versions 
 were failing to link; msgpack built fine but probably only the 
 msgpack.lib file (no final link).

 However, when I (counter-intuitively, for me) added pragma(lib, 
 "ws2_32"); to my own source files, it built successfully. 
 Should that have been necessary? it was not in any examples. 
 What gives?

 Thanks!
Yeah, right guess in the title ;) you have to put the "pragma lib" again. Take the use of "pragma lib" in the binding as an information saying "you have to do this too".
May 11 2018
next sibling parent TED_996 <ted_996 gmail.com> writes:
On Friday, 11 May 2018 at 12:53:08 UTC, Basile B. wrote:
 On Friday, 11 May 2018 at 12:35:52 UTC, TED_996 wrote:
 [...]
Yeah, right guess in the title ;) you have to put the "pragma lib" again. Take the use of "pragma lib" in the binding as an information saying "you have to do this too".
Okay, well, this information is nowhere to be seen (except *maybe* if you know where to look for). Besides, how am I supposed to know what every lib is using, including transitivity? There has to be a better way, right? A compiler warning? Maybe even a passing mention in the docs anywhere? (nowhere on this page, for example: https://dlang.org/spec/pragma.html, or on the msgpack page, or anywhere.)
May 11 2018
prev sibling parent TED_996 <ted_996 gmail.com> writes:
On Friday, 11 May 2018 at 12:53:08 UTC, Basile B. wrote:
 On Friday, 11 May 2018 at 12:35:52 UTC, TED_996 wrote:
 [...]
Yeah, right guess in the title ;) you have to put the "pragma lib" again. Take the use of "pragma lib" in the binding as an information saying "you have to do this too".
Sorry for double posting, but I find what you wrote hard to believe, especially since DCD, which uses msgpack, has no pragma(lib "ws2_32") in it. Can you cite a source, please?
May 11 2018