开发者

MSVS2010 linker error sadness - not entirely sure what is wrong

开发者 https://www.devze.com 2023-01-20 07:38 出处:网络
I am using a library of code from a tutorial for providing functionality for passing function开发者_StackOverflow社区 points of non-static member functions to a function that expects a static function

I am using a library of code from a tutorial for providing functionality for passing function开发者_StackOverflow社区 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消