为什么Visual Studio 2010寻找__thiscall而不是__cdecl调用约定

Why is visual studio 2010 looking for __thiscall rather than __cdecl calling conventions?

本文关键字:cdecl 约定 调用 thiscall Visual Studio 2010 寻找 为什么      更新时间:2023-10-16

总的来说,我正在尝试将opencv测试程序与我使用64位Visual Studio 2010 Professional编译的opencv库联系起来。错误示例如下:

1>webcamtest.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall cv::VideoCapture::isOpened(void)const " (?isOpened@VideoCapture@cv@@UBE_NXZ)

问题是为什么__thiscall,当它所链接opencv_highui249.dll包含

Symbol name  : ?isOpened@VideoWriter@cv@@UEBA_NXZ (public: virtual bool __cdecl cv::VideoWriter::isOpened(void)const )

__cdecl有意义,这表明库构建正确。链接测试程序时,正在搜索opencv_highui249.dll,因此构建标志似乎是正确的,但显然我错过了什么?

您确定使用了 x64 库吗?
Microsoft减少了 x64 中的调用约定。看这里。基本上现在一切都__fastcall.
编译器仍然可以使用 __thiscall,但会被忽略(MSDN 链接)。所以你的测试程序很好,但你的库看起来有问题。

__thiscall 是 VS 中对类的成员函数的默认调用约定。 也许头文件缺少__cdecl说明符,或者编译标志设置不正确,因此没有设置相关的 #define。

__thiscall 是 MSVC 中类成员函数的默认值,您要么需要使用相同的设置编译 OpenCV,要么在标头定义中显式使用 __cdecl