MSVS2010 linker error sadness - not entirely sure what is wrong - c++

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.

Related

C++ error when compiling Orbiter sample - LNK2019 unresolved external symbol

I have a very specific problem when trying to compile a 'sample' project for the Orbiter space flight simulator. I'm trying to compile the sample for the space shuttle 'Atlantis' using the preview version of Visual Studio 2019, and I'm getting an error like:
LNK2019 unresolved external symbol "__declspec(dllimport) public: __thiscall VESSEL2::VESSEL2(class VESSEL2 &&)" (__imp_??0VESSEL2##QAE#$$QAV0##Z) referenced in function "public: __thiscall Atlantis_SRB::Atlantis_SRB(class Atlantis_SRB &&)" (??0Atlantis_SRB##QAE#$$QAV0##Z)
This is happening in the Atlantis_SRB project. My code is located at:
C:\Orbiter2016\Orbitersdk\samples\Atlantis\
I have a lot of experience in software engineering, but I'm a C++ noob. I've looked at general help for this error, so I understand that there is something that needs to be linked, but I'm not sure what, or how to do it.
I looked at this question on the Orbiter forum:
https://www.orbiter-forum.com/showthread.php?t=24247
It suggests checking the following under project > properties:
Linker - Input - Additional libraries
and
Linker - Advanced - Library search paths
When I check under the 1st one, I have the following under Linker > Input > Additional Dependencies:
orbiter.lib;orbitersdk.lib;%(AdditionalDependencies)
The 2nd location (Linker - Advanced - Library search paths) doesn't exist.
I'm used to C# reference errors when dlls are missing from 'references' and know how to solve them quickly, but I'm not sure what to do with this type of C++ issue.
How do I identify what the specific problem is, and what do I need to link, where (and how?!)
I posted this problem on the excellent Orbiter forum, and cyph0r provided a fix there which works with VS2017:
https://www.orbiter-forum.com/showthread.php?p=589264&posted=1#post589264
Basically orbiter.lib seems to only be fully compatible 'out of the box' up to VS2013, and apparently the Atlantis sample compiles fine using VS2013. (I went back to using VS2017 and implemented cyph0r's fix, which works - I haven't tried VS2019):
This is the significant part of the error:
__declspec(dllimport) public: __thiscall VESSEL2::VESSEL2(class VESSEL2 &&)" (__imp_??0VESSEL2##QAE#$$QAV0##Z) referenced in function "public: __thiscall Atlantis_SRB::Atlantis_SRB(class Atlantis_SRB &&)
It's indicating that a move constructor is being referenced by the Atlantis_SRB class declaration, which can't be found in VS2017. This is the part that's indicating that the move constructor is being referenced:
__declspec(dllimport) public: __thiscall VESSEL2::VESSEL2(class VESSEL2 &&)
The fix is to remove the expectation that this move constructor exists, by editing the Atlantis.h file within the Atlantis sample. The link to the question on the Orbiter forum gives full details of what you need to do.

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

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.

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.

Unresolved external symbol error when compiling cpp-netlib v0.9

I am trying to build the cpp-netlib library from Visual Studio 2010 but get the following linker error:
error LNK2019: unresolved external symbol "bool __cdecl
boost::network::uri::detail::parse_uri_impl(class
boost::iterator_range,class std::allocator > > &,struct
boost::network::uri::detail::uri_parts_default_base &,struct
boost::network::tags::default_string)"
(?parse_uri_impl#detail#uri#network#boost##YA_NAAV?$iterator_range#V?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std###4#AAUuri_parts_default_base#1234#Udefault_string#tags#34##Z)
referenced in function "bool __cdecl
boost::network::uri::detail::parse_uri,class
std::allocator >,struct
boost::network::http::tags::http_default_8bit_tcp_resolve>(class
std::basic_string,class
std::allocator > &,struct
boost::network::uri::detail::uri_parts &)"
(??$parse_uri#V?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##Uhttp_default_8bit_tcp_resolve#tags#http#network#boost###detail#uri#network#boost##YA_NAAV?$basic_string#DU?$char_traits#D#std##V?$allocator#D#2##std##AAU?$uri_parts#Uhttp_default_8bit_tcp_resolve#tags#http#network#boost###0123##Z)
A little bit of digging turned up that this could be related to the version of Boost I'm using (1.46.1) but I have tried compiling against both 1.47.0 and 1.45.0 and get the same error.
What is required to get this library to compile?
After a lot of searching I found this post and this one from the creator of the library, mentioning:
An option to turn off the required external library to be linked with a macro (BOOST_NETWORK_NO_LIB). With this macro defined before
any cpp-netlib headers are included (or on the command line) the
functions that were made extern or just free functions at namespace
level are marked 'inline' and have their definitions pulled in
accordingly in each translation unit. This addresses Jeff Garland's
and others' concern of the need for an external library when using
cpp-netlib when it's always been header-only until 0.9. I'm still
wrestling with the thought of making the header-only behavior a
default, but I'm not married to the "external library as default"
decision either.
I am able to compile if I add that macro definition before my cpp-netlib headers like so:
#define BOOST_NETWORK_NO_LIB
#include <boost/network/protocol/http/client.hpp>
In the second post I found there is also mention of "You need to build/link against the uri library" which sounds like it might be a better solution.
Unfortunately my knowledge of c++ and boost isn't the best so I just went with what worked.
Any better approaches are welcome, though all I really wanted to do was compile the library so I can evaluate it for real use, so I'm happy right now.