I’m trying to get a UDP connection working for a game I’m making, the input for the socket is read via a second thread, so the game can continue running while it’s waiting for messages. I got it to work in a separate project, but when porting it over to my game code I get an Unresolved External Symbol error:
LNK2019: unresolved external symbol “void __cdecl receiveThread(void *)” (?receiveThread@@YAXPAX@Z) referenced in function “public: bool __thiscall Network::setupServerUDP(void)” (?setupServerUDP@Network@@QAE_NXZ)).
I’ve googled this and everyone says the Runtime Library should be set to Multi-threaded, which I did (In MVS 2010 I don’t think it’s even possible to set it to single-threaded) but it doesn’t resolve the error.
I’m sure it’s just some stupid option set to the wrong thing somewhere. But I just can’t think of what it is.
I’ve included ws2tcpip.h and I’ve linked to the correct library: #pragma comment(lib, “Ws2_32.lib”).
The only difference between my test project and the game project is that the test project was a Console application and the other is a Windows application, but I don’t see why that should be any problem. Thoughts?
Thanks for your help!
Cheers,
Maxim
The unresolved function is not
_beginthread, it’sreceiveThread. That’s your function – the thread entry point that you provide as a parameter to_beginthread. Did you write that function with the right calling convention? Is it reallycdecl? If you declare it as cdecl but implement without an explicit calling convention, that would cause a link error like this. For example, this code would cause a link error:To fix, make sure your implementation of
receiveThreaduses the cdecl convention or is declared asextern "C".For the record,
_beginthreadexexpects a stdcall function, not cdecl. With_beginthreadex, you don’t have to worry about conventions.