C++ linkage error - c++

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.

Related

MFC CString Linker error between two projects

I have 2 projects in c++ (MFC)
One is a library project which im using in the second one (an executable one).
They work together great, until I call a function from the regular project that takes a CString as argument. I get a linker error like this
error LNK2019: unresolved external symbol "public: void __thiscall
CTextDisplay::SetText1(class ATL::CStringT<wchar_t,class StrTraitMFC_DLL<wchar_t,
class ATL::ChTraitsCRT<wchar_t> > >)" (?SetText1#CTextDisplay##QAEXV?$CStringT#_WV?
$StrTraitMFC_DLL#_WV?$ChTraitsCRT#_W#ATL#####ATL###Z) referenced in function
"public: void __thiscall CManualPane::SetBeadCountFor(int,double)"
(?SetBeadCountFor#CManualPane##QAEXHN#Z) C:\source\IQ-Project\IQ\ManualPane.obj IQ
The executable project has its character set to UNICODE but the Library has it set to Multy-Byte chatacter set. I really can't change them without getting ridiculous amounts of errors.
Any suggestions?
Edit: The reason we have different settings in these two projects is because the Executable project is basically an external project that my group didn't build or create. We just had to bring it in and use it. The library project is something we've all been working on for a couple years.
When you include the headers of the library project in the executable, there is likely a typedef which is used in the declaration of the function. Since the executable uses UNICODE, the declaration is now in UNICODE. However, the library implementation is still in MultiByte and so the definition doesn't match the declaration leading to the linker error.
Look into how these typedefs are being setup, and you might be able to do some special #define, #undef around the included header.
In the end it proved to be a better idea to avoid having unicode and multybyte projects in the same solution so I moved it all to unicode and went from there

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

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.

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.

Error in Visual Studio

I get this error in visual studio and I don't know the reason. It doesn't even show the line number. Any clue?
Error 1 error LNK2028: unresolved
token (0A000041) "void __cdecl
free_img(struct Image *)"
(?free_img##$$FYAXPAUImage###Z)
referenced in function "double *
__cdecl calc_zernike_moments(struct Image const *,int,struct ZernikeBasis
const *)"
(?calc_zernike_moments##$$FYAPANPBUImage##HPBUZernikeBasis###Z) zernike_moments.obj TestLibrary
You have a routine
double * __cdecl calc_zernike_moments(struct Image const *foo,
int baz,
struct ZernikeBasis const *bar)
that calls a routine
void __cdecl free_img(struct Image *foo)
and you didn't supply the free_img() routine that matched to the linker.
free_img() is a function that is either defined in a .cpp file that you haven't included in the project, or it is in a DLL or static library that you haven't linked against. If it is the former, you need to search for the function in your source files and then add that .cpp file to the project. If it is the latter, then you need to identify which library provides free_img() and then locate the .lib file for that library. Then you can do this:
To add .lib files as linker input in the development environment
Open the project's Property Pages dialog box. For details, see Setting Visual C++ Project Properties.
Click the Linker folder.
Click the Input property page.
Modify the Additional Dependencies property.
(from http://msdn.microsoft.com/en-us/library/ba1z7822(VS.80).aspx)
You need to link the library. Where is the definition of free_img()?
You are just including the .h and not linking lib
The error is a linker error, not a compiler error, so there won't be a line number associated with it. Rather the error is telling you that your function calc_zernike_moments is calling another routine, free_img, that isn't defined in any of TestLibrary's compiled sources, so you need to provide it by other means. Typically what's missing here is the third-party library need be included in the project so the linker can bring in free_img's implementation.

Linking error in C++ - implementing a indexList

Linking...
Directory.obj : error LNK2019: unresolved external symbol "public: void __thiscall indexList<class entry,100>::read(class std::basic_istream<char,struct std::char_traits<char> > &)" (?read#?$indexList#Ventry##$0GE###QAEXAAV?$basic_istream#DU?$char_traits#D#std###std###Z) referenced in function _main
Getting this error and others associated with indexList implementation. I have included all the right files, not sure what this means?
indexList.h
indexList.cpp
Also, using VS .NET 2003 - They are under the "Source Files" and "Header Files" However, I tested with deleting the indexLish.h and the error doesn't change?
What you have is a class template. This means when the compiler needs to call a function, it will look at your template definition and generate the corresponding code as needed.
For example, the following probably has a compile-time error in it if tried to call it:
template <typename T>
void doSomething(const T& x) {
x->_this_function_does_not_exist_ever_();
}
But as long as you don't call doSomething you won't get errors.
The problem you have is that your header file tells the compiler "hey, these functions exist", but when the compiler tries to generate them it cannot find any definitions. (You cannot "compile" definitions in a source file and link them in, they must be visible to the caller.)
The most common solution is to simply define the entire class template in the .h or .hpp file.
Are you using visual studio then include both the files into the solution and then run.
Since you are using templates, the best way is to include the definition in .H file.
I read something from this book . And here is something it may help you too.