Building network package on Windows

Hi, I have been trying to build the package "network" from hackage (version 2.2.1.3) on Windows Vista, and I could really use some help. Building on the command line, or under cygwin completely failed (command line due to cabal not being able to execute something---possibly configure---although it would not say; cygwin first due to lack of gcc, which is tested but, apparently, the outcome ignored, and after gcc was installed some incompatibility with the header files which were detected but reported unusable). I managed to build the library under MinGW with msys without serious obstacles. I can also build my package against the result and all is well. Unfortunately, if I try to use my package to build an executable application I get a linker error, reporting a missing symbol during linking: C:\Users\diatchki\AppData\Roaming\cabal\network-2.2.1.3\ghc-6.10.3/libHSnetwork-2.2.1.3.a(Socket.o):fake:(.text+0xb014): undefined reference to `getnameinfo' collect2: ld returned 1 exit status Now, "getnameinfo" is present in the header files, and it is also defined in the library ws2_32.a which is being passed to GHC so I am not sure what is going on. Any ideas? Searching the web suggests that the problem may be somehow related to the standard calling conventions but I don't really understand. Also, if I understand correctly, this functionality is related to IPv6 support, which I do not need at the moment, so it would be great if it could be easily disabled in some way. Any ideas, suggestion, workarounds, etc. would be greatly appreciated, -Iavor PS: I am using GHC 6.10.3

Hello, Here is an update, in case anyone else runs into the same problem. My understanding, is that the problem was caused by a mistake in the "configure" script for the "network" package, which after (correctly) detecting that IPv6 functionality was not available on my platform, it (incorrectly) tried to "gain" this functionality by redefining the version of my platform. Concretely, apparently I have "Windows Vista Basic Home Edition", which seems to identify itself as version 0x400, while the missing functions are only available on versions of windows
= 0x501.
My workaround was to:
1. checkout the network package from the repository on code.haskell.com
2. modify configure.ac to comment out the section where it sets the
windows version to 0x501
3. autoreconf
4. build using the usual cabal way
Another thing to watch out for: if you already have packages that
were built against the old version of network, they will continue to
use that. So, I had to:
1. remove all of these packages,
2. remove the old version of network (to avoid confusion), and
3. then resintall the packages.
It would be nice if we had a more automatic way to do that (perhaps we
do, but I don't know it?). It seems that if this is not done GHC
could panic, which is what happened to me. I am not sure why that
happened but I am guessing that it was related to the fact that
interface to the package changed without its version changing.
In general, it seems a bad idea that the same version of the network
package exhibits different APIs, depending on the configuration of the
underlying system.
-Iavor
On Sat, Jun 6, 2009 at 9:43 PM, Iavor Diatchki
Hi, I have been trying to build the package "network" from hackage (version 2.2.1.3) on Windows Vista, and I could really use some help.
Building on the command line, or under cygwin completely failed (command line due to cabal not being able to execute something---possibly configure---although it would not say; cygwin first due to lack of gcc, which is tested but, apparently, the outcome ignored, and after gcc was installed some incompatibility with the header files which were detected but reported unusable).
I managed to build the library under MinGW with msys without serious obstacles. I can also build my package against the result and all is well. Unfortunately, if I try to use my package to build an executable application I get a linker error, reporting a missing symbol during linking: C:\Users\diatchki\AppData\Roaming\cabal\network-2.2.1.3\ghc-6.10.3/libHSnetwork-2.2.1.3.a(Socket.o):fake:(.text+0xb014): undefined reference to `getnameinfo' collect2: ld returned 1 exit status
Now, "getnameinfo" is present in the header files, and it is also defined in the library ws2_32.a which is being passed to GHC so I am not sure what is going on. Any ideas? Searching the web suggests that the problem may be somehow related to the standard calling conventions but I don't really understand. Also, if I understand correctly, this functionality is related to IPv6 support, which I do not need at the moment, so it would be great if it could be easily disabled in some way.
Any ideas, suggestion, workarounds, etc. would be greatly appreciated, -Iavor
PS: I am using GHC 6.10.3

On Mon, Jun 8, 2009 at 2:04 AM, Iavor Diatchki
Hello, Here is an update, in case anyone else runs into the same problem.
My understanding, is that the problem was caused by a mistake in the "configure" script for the "network" package, which after (correctly) detecting that IPv6 functionality was not available on my platform, it (incorrectly) tried to "gain" this functionality by redefining the version of my platform. Concretely, apparently I have "Windows Vista Basic Home Edition", which seems to identify itself as version 0x400, while the missing functions are only available on versions of windows
= 0x501.
My workaround was to: 1. checkout the network package from the repository on code.haskell.com 2. modify configure.ac to comment out the section where it sets the windows version to 0x501 3. autoreconf 4. build using the usual cabal way
Do you mind filing a bug at http://trac.haskell.org/network so we can track this problem and hopefully fix it in the future (I'm afraid someone with better Windows knowledge will have to do it)? Thanks, Johan

On Mon, Jun 8, 2009 at 02:04, Iavor Diatchki
Hello, Here is an update, in case anyone else runs into the same problem.
My understanding, is that the problem was caused by a mistake in the "configure" script for the "network" package, which after (correctly) detecting that IPv6 functionality was not available on my platform, it (incorrectly) tried to "gain" this functionality by redefining the version of my platform. Concretely, apparently I have "Windows Vista Basic Home Edition", which seems to identify itself as version 0x400, while the missing functions are only available on versions of windows
= 0x501.
0x400 is, if I'm not mistaken, Windows 95. Vista is 0x600 [1]. I don't think they *identify* themselves as such; rather, the program itself specifies what Windows versions it wants to be able to run on. In particular, the macros _WIN32_WINNT and WINVER should be defined as the *minimum* platform version on which the compiled binary is to work. Therefore, if functionality from XP (0x501) is needed, it is perfectly okay to redefine these macros to 0x501. This will flip some switches in included header files that enable declarations for the desired functionality. Of course, the binary will then only run on platforms that actually have this functionality. Hope that clears things up a bit. Thomas [1] http://msdn.microsoft.com/en-us/library/aa383745.aspx

Hi,
Interesting. In that case, does anyone have any ideas about the
linker errors?
-Iavor
On Mon, Jun 8, 2009 at 12:42 AM, Thomas ten Cate
On Mon, Jun 8, 2009 at 02:04, Iavor Diatchki
wrote: Hello, Here is an update, in case anyone else runs into the same problem.
My understanding, is that the problem was caused by a mistake in the "configure" script for the "network" package, which after (correctly) detecting that IPv6 functionality was not available on my platform, it (incorrectly) tried to "gain" this functionality by redefining the version of my platform. Concretely, apparently I have "Windows Vista Basic Home Edition", which seems to identify itself as version 0x400, while the missing functions are only available on versions of windows
= 0x501.
0x400 is, if I'm not mistaken, Windows 95. Vista is 0x600 [1]. I don't think they *identify* themselves as such; rather, the program itself specifies what Windows versions it wants to be able to run on.
In particular, the macros _WIN32_WINNT and WINVER should be defined as the *minimum* platform version on which the compiled binary is to work. Therefore, if functionality from XP (0x501) is needed, it is perfectly okay to redefine these macros to 0x501. This will flip some switches in included header files that enable declarations for the desired functionality. Of course, the binary will then only run on platforms that actually have this functionality.
Hope that clears things up a bit.
Thomas

On Sun, Jun 7, 2009 at 5:04 PM, Iavor Diatchki
Here is an update, in case anyone else runs into the same problem.
Thanks for following up. I wrote the code that performs that check, but unfortunately I don't have access to all of the permutations of Windows that are out there, so my ability to test is rather limited. I'm sorry for the trouble it caused you. Perhaps Vista Home Basic doesn't have IPv6 support? If that conjecture is true, I'm not sure how I'd have found it out :-( More likely, the name mangling is going wrong. As for your point that the network package exhibits different APIs depending on the underlying system, that's true, but it's hard to avoid. Writing a compatibility API for systems that don't have functioning IPv6 APIs is a chunk of boring work, and I had thought that such systems were rare. Anyway, please do file a bug, and we'll take the discussion of how to reproduce and fix your problem there. Thanks, Bryan.

Hi,
As Thomas pointed out, it is not clear if this is a bug, or if there
is something confused between the different versions of Windows and
MinGW (or I just did something wrong) but I'll make a ticket so that
we can track the issue. I am by no means a Windows developer but I
would be happy to try out fixes/ideas on my Windows machine as I think
that it is important that we have as good support for Windows as we do
on the various Unix-like systems.
-Iavor
On Mon, Jun 8, 2009 at 1:23 PM, Bryan O'Sullivan
On Sun, Jun 7, 2009 at 5:04 PM, Iavor Diatchki
wrote: Here is an update, in case anyone else runs into the same problem.
Thanks for following up. I wrote the code that performs that check, but unfortunately I don't have access to all of the permutations of Windows that are out there, so my ability to test is rather limited. I'm sorry for the trouble it caused you. Perhaps Vista Home Basic doesn't have IPv6 support? If that conjecture is true, I'm not sure how I'd have found it out :-( More likely, the name mangling is going wrong.
As for your point that the network package exhibits different APIs depending on the underlying system, that's true, but it's hard to avoid. Writing a compatibility API for systems that don't have functioning IPv6 APIs is a chunk of boring work, and I had thought that such systems were rare.
Anyway, please do file a bug, and we'll take the discussion of how to reproduce and fix your problem there.
Thanks, Bryan.

Hi,
OK, I think that I found and fixed the problem. As Thomas pointed
out, the configure script is not wrong. The problem turned out to be
the foreign import for "getnameinfo" (this was the missing symbol).
Attached to this e-mail should be a darcs patch that fixes the
problem.
-Iavor
On Mon, Jun 8, 2009 at 4:48 PM, Iavor Diatchki
Hi, As Thomas pointed out, it is not clear if this is a bug, or if there is something confused between the different versions of Windows and MinGW (or I just did something wrong) but I'll make a ticket so that we can track the issue. I am by no means a Windows developer but I would be happy to try out fixes/ideas on my Windows machine as I think that it is important that we have as good support for Windows as we do on the various Unix-like systems. -Iavor
On Mon, Jun 8, 2009 at 1:23 PM, Bryan O'Sullivan
wrote: On Sun, Jun 7, 2009 at 5:04 PM, Iavor Diatchki
wrote: Here is an update, in case anyone else runs into the same problem.
Thanks for following up. I wrote the code that performs that check, but unfortunately I don't have access to all of the permutations of Windows that are out there, so my ability to test is rather limited. I'm sorry for the trouble it caused you. Perhaps Vista Home Basic doesn't have IPv6 support? If that conjecture is true, I'm not sure how I'd have found it out :-( More likely, the name mangling is going wrong.
As for your point that the network package exhibits different APIs depending on the underlying system, that's true, but it's hard to avoid. Writing a compatibility API for systems that don't have functioning IPv6 APIs is a chunk of boring work, and I had thought that such systems were rare.
Anyway, please do file a bug, and we'll take the discussion of how to reproduce and fix your problem there.
Thanks, Bryan.

On Mon, Jun 8, 2009 at 10:18 PM, Iavor Diatchki
OK, I think that I found and fixed the problem. As Thomas pointed out, the configure script is not wrong. The problem turned out to be the foreign import for "getnameinfo" (this was the missing symbol).
So it was the name mangling! Great, thanks for the patch. It's applied.

On Sat, 2009-06-06 at 21:43 -0700, Iavor Diatchki wrote:
Hi, I have been trying to build the package "network" from hackage (version 2.2.1.3) on Windows Vista, and I could really use some help.
Unfortunately, if I try to use my package to build an executable application I get a linker error, reporting a missing symbol during linking: C:\Users\diatchki\AppData\Roaming\cabal\network-2.2.1.3\ghc-6.10.3/libHSnetwork-2.2.1.3.a(Socket.o):fake:(.text+0xb014): undefined reference to `getnameinfo' collect2: ld returned 1 exit status
I saw some other people run into this today.
Now, "getnameinfo" is present in the header files, and it is also defined in the library ws2_32.a which is being passed to GHC so I am not sure what is going on. Any ideas?
Searching the web suggests that the problem may be somehow related to the standard calling conventions but I don't really understand.
Right. The getnameinfo in ws2_32.a uses the stdcall calling convention. The actual linker symbol for it is "_getnameinfo@28". If it used the ccall convention then it's linker symbol name would be "_getnameinfo". The FFI decl for getnameinfo uses ccall. So that's why we get the error. The current version uses a C wrapper for this function (for unrelated reasons) and this has the side effect that the C compiler picks up the correct calling convention from the C header files. We would be able to catch errors like this if we had a tool that would check the Haskell FFI decls match the C headers. Of course c2hs already does this, but only for generating correct FFI decls in the first place. It cannot be used in a mode where it checks existing code. That might be a useful extension though since very few projects seem to use c2hs to generate correct imports in the first place. It also does not currently check stdcall vs ccall calling convention but it could fairly easily be extended to do so (since it parses those attributes). -- Duncan Coutts, Haskell Consultant Well-Typed LLP, http://www.well-typed.com/
participants (5)
-
Bryan O'Sullivan
-
Duncan Coutts
-
Iavor Diatchki
-
Johan Tibell
-
Thomas ten Cate