MSVS2010 链接器错误悲伤 - 不完全确定出了什么问题
我正在使用教程中的代码库,提供将非静态成员函数的函数点传递给需要静态函数指针的函数的功能,可能有助于了解我正在起诉的内容,因此这里是链接 http://www.codeproject.com/KB/cpp/thunk32.aspx 此代码使用Boost 库,我已经从中下载并设置了或多或少的所有内容。
在 Thunk 库中,其中一个头文件有一个部分
#define BOOST_PP_ITERATION_PARAMS_1 (3,(0,THUNK32_MAX_ARGS,"Thunk32_template.h"))
??=include BOOST_PP_ITERATE()
#undef BOOST_PP_ITERATION_PARAMS_1
,但是这给了我大量的错误,我可以通过将其更改为来解决
#define BOOST_PP_ITERATION_PARAMS_1 (3,(0,THUNK32_MAX_ARGS,"Thunk32_template.h"))
#include BOOST_PP_ITERATE()
#undef BOOST_PP_ITERATION_PARAMS_1
此问题。下载的代码作为第二个项目包含在我的解决方案中,该项目能够愉快地编译和构建。但是我使用此代码的项目存在链接问题,为了避免人们询问,我收到这些错误消息
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)
我认为这是试图说构造函数和析构函数未声明并且我的 WebCamera.Init() 也搞砸了。我已确保 Thunk32 项目导出的库包含在我的其他项目中,但我仍然收到这些错误。
我想知道我是否做出了正确的假设,即 ??=include
应该更改为 #include
,如果是,我做错了什么或失败了这样做会导致这些链接器错误。或者,如果您可以为我提供一种不同的方式来将函数指针传递给非静态成员函数,那就太棒了。
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
??=
是#
字符的“三字母”序列。根据标准,三字母应该作为处理的第一步之一来处理(在第一阶段 - 在预处理器处理指令之前),所以:应该相当于:
所以你应该能够使用这种形式(我想知道为什么三字母表首先被放在那里 - 也许是某种邪恶的笑话?)
但是,三字母表会导致问题和混乱(可能超过它们的帮助),因此编译器似乎正朝着警告它们和/或默认不这样做的方向发展处理它们。 VS 2010 中的编译器默认关闭三字母处理 - 您必须使用
/Zc:trigraphs
选项将其打开。有关更多详细信息,请参阅 C++ 中 Trigraph 序列的用途?。
??=
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:Should be equivalent to:
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.
啊,埃纳尔,好人。这些天在做 flash 和 Sharepoint 的事情,哎呀。挪威语,可以解释三字母。
无论如何,没什么复杂的,你只是忘记告诉链接器查看一些库。右键单击您的项目,Project Dependencies,勾选 Thunk 项目。这可以确保 Thunk32.lib 得到查看并解析 ctor 和 dtor。
再次右键单击“属性”、“链接器”、“其他依赖项”,添加“winmm.lib”。这解决了 capCreateCaptureWindow 符号。
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.
您是否在 indev::Thunk32Base 类中声明了一个构造函数和一个析构函数,而您忘记在其 cpp 文件中定义该构造函数和析构函数?
Do you have a constructor and a destructor declared in the indev::Thunk32Base class that you forgot to define in its cpp file?
好的,我现在已经成功解决了这个问题。
Michael Burr nicley 说
??=
与输入基本相同#
但没有哈希符号的人也可以输入它,请参阅 C++ 中三字母序列的用途?Hans Passant 然后帮我开始购买出租我知道我还没有完全联系起来。我需要右键单击我的主项目,选择“项目依赖项”,然后选择具有 thunk32 代码的其他项目。我还需要告诉我的主项目查看 Thunk 项目保存库的位置,结果它位于我文档的一个文件夹中(解释一下!)。我还需要添加 Thunk32d.lib(注意“d”,因为我处于调试模式。Hans 说我需要
winmm.lib
但事实证明(当谷歌搜索该函数时)给我我需要Vfw32.lib
的错误,谢谢大家!我希望通过给出这样的完整答案可以帮助其他有类似问题的人。
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 neededVfw32.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.