When using C ++ for socket programming, the following error occurs:
1> ------ generated: Project: netclient, configuration: Debug Win32 ------
1> netclient. cpp
1> C:/My Documents ents/Visual Studio 2010/projects/NETServer/netclient. CPP (48): Warning c4996: 'gets': This function or variable may be unsafe. consider using gets_s instead. to disable deprecation, use _ crt_secure_no_warnings. see online help for details.
1> D:/vs2010/VC/include/stdio. H (277): see the "gets" statement.
1> C:/My Documents ents/Visual Studio 2010/projects/NETServer/netclient. CPP (59): Warning c4996: 'sprintf': This function or variable may be unsafe. consider using sprintf_s instead. to disable deprecation, use _ crt_secure_no_warnings. see online help for details.
1> D:/vs2010/VC/include/stdio. H (371): see the "sprintf" statement.
1> netclient. OBJ: Error lnk2019: external symbol that cannot be parsed _ closesocket @ 4, which is referenced in function _ main
1> netclient. OBJ: Error lnk2019: external symbol that cannot be parsed _ inet_ntoa @ 4, which is referenced in function _ main
1> netclient. OBJ: Error lnk2019: external symbol that cannot be parsed _ recvfrom @ 24, which is referenced in function _ main
1> netclient. OBJ: Error lnk2019: external symbol that cannot be parsed _ sendto @ 24, which is referenced in function _ main
1> netclient. OBJ: Error lnk2019: external symbol that cannot be parsed _ htons @ 4, which is referenced in function _ main
1> netclient. OBJ: Error lnk2019: external symbol that cannot be parsed _ inet_addr @ 4, which is referenced in function _ main
1> netclient. OBJ: Error lnk2019: external symbol that cannot be parsed _ socket @ 12, which is referenced in function _ main
1> netclient. OBJ: Error lnk2019: external symbol that cannot be parsed _ wsacleanup @ 0, which is referenced in function _ main
1> netclient. OBJ: Error lnk2019: external symbol that cannot be parsed _ wsastartup @ 8, which is referenced in function _ main
1> C:/My Documents ents/Visual Studio 2010/projects/NETServer/debug/netclient.exe: Fatal error lnk1120: 9 unresolvable External commands
============ Generate: 0 successful, 1 failed, 0 latest, skipped 0 ==========
The solution is as follows:
Add the following code after the include statement of the CPP file:
# Pragma comment (Lib, "ws2_32.lib ")
# Pragma comment (Lib, "ws2_32.lib ")
This will solve the problem.