Unresolved External Symbol receiveThread (that's the entry point for _beginthread) - c++

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's receiveThread. 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 really cdecl? 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:
extern "C" { void receiveThread(void*); } //There's a cdecl function somewhere
//...
_beginthread(receiveThread, 0, 0); //Let's refer to it
//...
void receiveThread(void *p) //But this is not it! It's stdcall.
{
//Do something
}
To fix, make sure your implementation of receiveThread uses the cdecl convention or is declared as extern "C".
For the record, _beginthreadex expects a stdcall function, not cdecl. With _beginthreadex, you don't have to worry about conventions.

The error is telling you that the linker cannot find the implementation for the function receiveThread which I'm guessing is declared in ws2tcpip.h
If Ws2_32.lib contains the implementation, try adding it to linker -> additional dependencies -> inputs under the properties menu for the project, assuming you're using visual studio.

Related

Source code of CvCaptureFromFile(..)

I want to use the source code of the CvCaptureFromFile(..) function as I do not want to use OpenCV library functions in my project. So I went inside the function by pressing F10,F11 and I copied the things I needed and converted them into C code. Till now everything was ok.
But when I tried to run I am getting linking error inside the function icvIntFFMPEG(void)
the errors are as follows:
Error 1 error LNK2019: unresolved external symbol
"__declspec(dllimport) void * __stdcall GetProcAddress(struct
HINSTANCE__ *,char const *)"
(__imp_?GetProcAddress##YGPAXPAUHINSTANCE__##PBD#Z) referenced in
function "void __cdecl icvInitFFMPEG(void)" (?icvInitFFMPEG##YAXXZ)
Error 2 error LNK2019: unresolved external symbol "struct HINSTANCE__
* __stdcall LoadLibrary(char const *)" (?LoadLibrary##YGPAUHINSTANCE__##PBD#Z) referenced in function "void
__cdecl icvInitFFMPEG(void)" (?icvInitFFMPEG##YAXXZ)
I copied everything as it is in the source code. Any idea where I am going wrong? How do I solve this error?
UPDATE: IF I wrap the header file (where I was coping the source code) inside an extern "C" something like this-
extern "C" {
#include "defination.h"
}
Then the first error is gone, and the error with loadLibrary changes to
error LNK2019: unresolved external symbol __imp__LoadLibrary#4 referenced in function _icvInitFFMPEG
OpenCv uses ffmpeg - which is a really big project. And ffmpeg uses some other tools behind curtains. You may want to go using ffmpeg, but to take the source code from ffmpeg itself is foolish - you will spend years fiddling with that code - really.
So, decide on a video input library - be it OpenCV, ffmpeg, Direct3D or whatever, and use it.
Do not cling yourself on the idea that 'you cannot use external libraries' because you can't go without them. It takes years to develop such a library - I am pretty sure you do not want to go that way.
Well, it seems your get unresolved calls to LoadLibrary()/GetProcAddress() functions that are inside Kernel32.dll. What IDE/project type are you using? Kernel32.lib should be linked in by default unless /NODEFAULTLIB is specified somewhere, at least as far as I remember. You can try to add #pragma comment(lib, "kernel32.lib") to the file where you copied the code, but without more info about your setup it is hard to answer what is causing this.

Linking error: LNK2019 & LNK1120

First I had some OpenCL code and when I put it away in another function, I got this error, then I thought maybe its something with OpenCL, but now even my every normal code suddenly appears to report this error whenever I make new function and put main function code in those functions. I have rechecked that prototypes, functions calls and function definitions are exactly same and matches, also since I have this problem with those functions in which there are more arguments like upto 8 or 10 but I read that C/C++ functions supports more 50 or so arguments passing. The error information is:
ImgConv.obj : error LNK2019: unresolved external symbol "void __cdecl function(.............) (?conv_ser##YAXPBMPAM10HHH#Z) referenced in function _main
fatal error LNK1120: unresolved externals
I am reporting error that has lot of forum entries and solution information such as linking some library function or functions prototyping mistakes etc, I have read them but there is non related to my problem.
Check the linker input settings in your project configuration and make sure that the appropriate libraries are included (or add them to the project itself). Visual Studio doesn't do this automatically just because you add the source code to your project.
If 'conv_ser' is a function that you created make sure that the implementation for that function is available in the project. Double check to make sure that the arguments in the prototype (typically in the header) match that of the any implementation you have added.
Have you tried deleting all instances of void __cdecl function? Just search through your project and comment it out. See if your code will compile after this.

C++ linkage error

I compile in Visual studio 2008 and get this error. I have researched linkage error but am still uncertain to what it is. This is the finished code to a poker game so I would rather not post the code. Can someone translate this error message for me?
error LNK2019: unresolved external symbol "void __cdecl betFold(double)" (?betFold##YAXN#Z) referenced in function "void __cdecl flopAction(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?flopAction##YAXV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std###Z) OH-DLL.obj
Your function void flopAction(std::string arg) uses a function betFold(double) that gets referenced and declared in some header, but is not implemented so that the linker is able to find it.
It means that you have declared this method but not defined it. Or at least the linker cannot find the definition, either because it’s in a library that you didn’t reference or else because it’s in an object file (source file) that is not part of your build process.
Sound like you forgot to specify the *.lib file that belongs to the *.dll. You can edit the list under your Project Property Pages -> Configuration properties -> Linker -> Input, remember to do this for the Debug and Release configuration.
And please try to refrain from phrases like wtf etc :)
Also, you could check your signature(function declaration), so that it contains only the type in it's parameter lists, while inside the definition(.cpp file), it contains both the type and parameter names. For eg,
in the .h file where the declaration sits:
void myfunc(int, char*);
and in the .cpp file where the definition sits:
void myfunc(int num, char* name)
{
//
}
I learnt this before in my college, but don't sure if Dev C++ supports it, left this things for a long time ago, just using Borland at that time.
hope this helps.
thanks.

Resolving 'LNK2019 unresolved external symbol' on DirectDrawCreate

I've been attempting to get DirectDraw to function on a CE5.0 framework for the last week and I'm running into some very odd issues.
ddrval = DirectDrawCreate(NULL, &lpDD, NULL);
When I have this function in my code, I get "error LNK2019: unresolved external symbol _DirectDrawCreate referenced in function "bool __cdecl DirectDrawInit(struct HWND__ *)" (?DirectDrawInit##YA_NPAUHWND__###Z)"
The function itself exists in the .h, as I can jump directly to it, which makes me think I'm missing a library, but I have no idea how to check or fix this as it is being built for a remote CE5.0 device. I also run into a few other subtile hints that I am missing something such as LR_CREATEDIBSECTION and other LR constants not existing and small differences in types (HBITMAP not being liked and LPCWSTR being prefered).
Any assistance would be greatly appreciated. Just as a note, WindowsMobile5.0 code doesn't work on the device, and if I comment out the offending function the code compiles and runs (it's not being used as DirectDrawCreate is kind of important but the LNK error goes away)
You should link your program with ddraw.lib. This is the import lib for direct draw on windows mobile.

MSVS2010 linker error sadness - not entirely sure what is wrong

I am using a library of code from a tutorial for providing functionality for passing function points of non-static member functions to a function that expects a static function pointer, probably helps to know what I am suing, so here is the link http://www.codeproject.com/KB/cpp/thunk32.aspx This code uses the Boost library, which I have downloaded and set-up more or less everything from.
In the Thunk library, one of the header files has a section that reads
#define BOOST_PP_ITERATION_PARAMS_1 (3,(0,THUNK32_MAX_ARGS,"Thunk32_template.h"))
??=include BOOST_PP_ITERATE()
#undef BOOST_PP_ITERATION_PARAMS_1
but this gives me epic amounts of errors, which I can solve by changing it to
#define BOOST_PP_ITERATION_PARAMS_1 (3,(0,THUNK32_MAX_ARGS,"Thunk32_template.h"))
#include BOOST_PP_ITERATE()
#undef BOOST_PP_ITERATION_PARAMS_1
This code that is downloaded is included in my solution as a second project, which is able to compile and build happily. But my project that is using this code has issues linking, to save people asking, I get these error messages
1>WebCamera.obj : error LNK2019: unresolved external symbol "protected: __thiscall indev::Thunk32Base::Thunk32Base(void)" (??0Thunk32Base#indev##IAE#XZ) referenced in function "public: __thiscall indev::Thunk32<class WebCamera,void __cdecl(struct HWND__ *,struct videohdr_tag *)>::Thunk32<class WebCamera,void __cdecl(struct HWND__ *,struct videohdr_tag *)>(void)" (??0?$Thunk32#VWebCamera##$$A6AXPAUHWND__##PAUvideohdr_tag###Z#indev##QAE#XZ)
1>WebCamera.obj : error LNK2019: unresolved external symbol "protected: __thiscall indev::Thunk32Base::~Thunk32Base(void)" (??1Thunk32Base#indev##IAE#XZ) referenced in function "public: __thiscall indev::Thunk32<class WebCamera,void __cdecl(struct HWND__ *,struct videohdr_tag *)>::~Thunk32<class WebCamera,void __cdecl(struct HWND__ *,struct videohdr_tag *)>(void)" (??1?$Thunk32#VWebCamera##$$A6AXPAUHWND__##PAUvideohdr_tag###Z#indev##QAE#XZ)
1>WebCamera.obj : error LNK2019: unresolved external symbol _capCreateCaptureWindowA#32 referenced in function "public: bool __thiscall WebCamera::Init(struct HWND__ *)" (?Init#WebCamera##QAE_NPAUHWND__###Z)
I think this is trying to say that the constructor and destructor are not declared and that my WebCamera.Init()is messed up as well. I have made sure that the library that the Thunk32 project exports is included in my other project, but still I get these errors.
I would like to know if I have made the correct assumption that ??=include should have been changed to #include and if I have, what have I done wrong or failed to do that results in these linker errors. Or if you can provide me with a different way of being able to pass a function pointer to a non-static member function that would be awesome.
Thanks
??= is a "trigraph" sequence for the # character. according to the standard, trigraphs are supposed to be handled as one of the first steps in processing (in phase 1 - before the preprocessor handles directives),so:
??=include "whatever"
Should be equivalent to:
#include "whatever"
so you should be able to use that form (I wonder why the trigraph was put there in the first place - some sort of evil joke perhaps?)
However, trigraphs cause problems and confusion (probably more than they help), so compilers seem to be moving towards warning about them and/or defaulting to not handling them. The compiler in VS 2010 has trigraph processing turned off by default - you have to use the /Zc:trigraphs option to turn it on.
See Purpose of Trigraph sequences in C++? for more details.
Ah, Einar, good man. Doing flash and Sharepoint stuff these days, ouch. Norwegian, might explain the trigraphs.
Anyhoo, nothing complicated, you just forgot to tell the linker to look at some libraries. Right-click your project, Project Dependencies, tick the Thunk project. That makes sure that Thunk32.lib gets looked at and resolves the ctor and dtor.
Right-click again, Properties, Linker, Additional dependencies, add "winmm.lib". That resolves the capCreateCaptureWindow symbol.
Do you have a constructor and a destructor declared in the indev::Thunk32Base class that you forgot to define in its cpp file?
Ok, so I have managed to solve this now.
Michael Burr nicley said that ??= is basically the same as typing # but in a way that people who dont have the hash symbol can type it, see Purpose of Trigraph sequences in C++?
Hans Passant then got the ball rolling for me buy letting me know that I had not fully linked in stuff. I needed to right click on my main project, select 'Project Dependencies' and select my other project that has the thunk32 code. I also needed to tell my main project to look at where the Thunk project is saving the lib, which turned out to be in a folder in my documents (explain that one!). I also needed to add the Thunk32d.lib (note the 'd' because I was/am in debug mode. Hans said that I needed winmm.lib but it turned out (when googling the function that was giving me the error that I needed Vfw32.lib instead.
Thanks guys! I hope that by giving the full answer like this it can help some one else who has a similar problem.