简体   繁体   中英

How to build a Winsock2 (WS2_32.lib) application targeting Windows XP with Visual Studio 2017

I have an application written in C++ that uses socket (Winsock2.h). It has been developed on Windows 10 and it builds and runs fine on Windows 10. There is an old XP machine on which that application has to run (the machine cannot be upgraded as it contains legacy code that does not run on newer systems), but when I try to run the application on it I get the error: "The procedure entry point WSAPoll could not be located in the dynamic link library WS2_32.dll".

I tried the following:

  1. I downloaded Visual Studio Express 2010 on a XP box and tried to build the application on it:
    • The code does not compile, because it uses libpqxx library (I suspect that libpqxx uses some c++11 code, that is not fully supported by VS2010);
  2. I downloaded the XP toolset (v141_xp) for Visual Studio 2017 and built the application on Windows 10 (I have also downloaded and installed on XP the Microsoft Visual C++ Redistributable for Visual Studio 2017);

    • I got the same "The procedure entry point WSAPoll could not be located in the dynamic link library WS2_32.dll" error.
  3. I tried to use winsock.h and link the application to wsock32.lib:

    • I got the same entry point error on WS2_32.lib (probably VS links the application to WS2_32.lib even if I specified to use wsock32.liB).

Is there a way to build on VS2017 using the xp toolset an application that uses Ws2_32.lib targeting XP?

EDIT 2019-05-03 10:30

As noticed by cprogrammer and Remy Lebeau WSAPoll does not exist in XP. The point is that I do not use WSAPoll in my code. So I followed the suggestion of Retired Ninja and I wrote from scratch an application using WinSock2 starting from the very basic and adding functions step by step(*). Well, all of my code worked well. The point is that I included also another library - libpqxx - and probably it uses WSAPoll.

Ok, I still have a problem, but at least I know where it is

(*) By the way, I already tried the same in the part of my code that uses WS2_32.lib, but as the problem was in another library I still got the error, so the suggestion to start from scratch really helped.

Accortding to docs , for WSAPoll , the minimum supported client is Windows 8.1, Windows Vista [desktop apps | UWP apps]

Cannot be used for applications targeting Windows XP.

Your app (or one of its dependancies) is static linking to WSAPoll() , which simply does not exist on XP, it was introduced in Vista. Whatever code your app uses that utilizes WSAPoll() will have to be rewritten for XP. For instance, by using GetProcAddress() to access WSAPoll() dynamically instead of statically, and using a fallback ( select() , WSAAsyncSelect() , WSAEventSelect() , etc) when WSAPoll() is not available.

Actually, the code should be rewritten - period, since WSAPoll() is broken and even Microsoft has gone on record saying that WSAPoll() will not be fixed and should not be used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM