问题
I'm currently trying to learn WinSock coding from http://johnnie.jerrata.com/winsocktutorial/ however when I compile my listening socket, I get 9 error LNK2019: unresolved external symbol
errors. They all look to be the same function names that are used in the code prefixed with an underscore after the function name it says referenced in function _WinMain@16
This also happens when I run the code example that is available for download, so I don't think I've made a mistake.
What is an unresolved external and how do I go about fixing one? I can post the code if needed but it's all visibile on that link. I'm using Visual Studios 2010, Win32 project.
回答1:
Unresolved external is linker error, telling you that you didn't link symbols you are getting those unresolved externals to into the binary.
Quoting from the site you linked:
Feel free to download the entire tutorial code listing. Remember that any code presented in this tutorial should be linked with the Winsock library, usually wsock32.lib or something similarly named. Also, when using code exactly as presented in the tutorial in your own IDE (Dev-C++, Microsoft VC++, C++ Builder, etc.), choose to build a Windows project with a WinMain() to avoid errors.
One of ways to link it is:
#pragma comment(lib, "wsock32.lib")
Also, consider using Boost.Asio instead of raw WinSock.
来源:https://stackoverflow.com/questions/11111344/win32-error-lnk2019-unresolved-external-symbol