visualstudio2008-如何让VS2008在C++项目中使用__cdecl而不是__thiscall
visual studio 2008 - How to get VS2008 to use __cdecl rather than __thiscall in C++ project?
我正试图在Visual Studio 2008中构建一个开源C++项目。我加载了解决方案文件,所有的东西都编译了,但由于找不到某些方法,我收到了一堆链接错误。使用DUMPBIN后。EXE来检查有问题的.lib文件,我可以看到问题是什么:.lib中的方法的签名中都有__cdecl
,而链接器正在寻找具有__thiscall
的等效方法。
如何让VS 2008改用__cdecl
?
注:该项目是CCV的一个分支,CCV是一个基于OpenCV的多点触摸跟踪程序。该分叉的目的是通过相机制造商提供的FlyCapture2库为名为Flea3的相机提供支持。以下是链接器错误:
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::Image::Image(void)" (__imp_??0Image@FlyCapture2@@QAE@XZ) referenced in function "public: __thiscall ofxFlea3::ofxFlea3(void)" (??0ofxFlea3@@QAE@XZ)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall FlyCapture2::Image::~Image(void)" (__imp_??1Image@FlyCapture2@@UAE@XZ) referenced in function "public: __thiscall ofxFlea3::ofxFlea3(void)" (??0ofxFlea3@@QAE@XZ)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::Camera::Camera(void)" (__imp_??0Camera@FlyCapture2@@QAE@XZ) referenced in function "public: __thiscall ofxFlea3::ofxFlea3(void)" (??0ofxFlea3@@QAE@XZ)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall FlyCapture2::Camera::~Camera(void)" (__imp_??1Camera@FlyCapture2@@UAE@XZ) referenced in function "public: __thiscall ofxFlea3::ofxFlea3(void)" (??0ofxFlea3@@QAE@XZ)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall FlyCapture2::Error::~Error(void)" (__imp_??1Error@FlyCapture2@@UAE@XZ) referenced in function "void __cdecl PrintError(class FlyCapture2::Error)" (?PrintError@@YAXVError@FlyCapture2@@@Z)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void __thiscall FlyCapture2::Error::PrintErrorTrace(void)const " (__imp_?PrintErrorTrace@Error@FlyCapture2@@UBEXXZ) referenced in function "void __cdecl PrintError(class FlyCapture2::Error)" (?PrintError@@YAXVError@FlyCapture2@@@Z)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class FlyCapture2::Error __thiscall FlyCapture2::BusManager::GetCameraFromIndex(unsigned int,class FlyCapture2::PGRGuid *)" (__imp_?GetCameraFromIndex@BusManager@FlyCapture2@@UAE?AVError@2@IPAVPGRGuid@2@@Z) referenced in function "public: void __thiscall ofxFlea3::listDevices(void)" (?listDevices@ofxFlea3@@QAEXXZ)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall FlyCapture2::BusManager::~BusManager(void)" (__imp_??1BusManager@FlyCapture2@@UAE@XZ) referenced in function "public: void __thiscall ofxFlea3::listDevices(void)" (?listDevices@ofxFlea3@@QAEXXZ)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::Error::Error(class FlyCapture2::Error const &)" (__imp_??0Error@FlyCapture2@@QAE@ABV01@@Z) referenced in function "public: void __thiscall ofxFlea3::listDevices(void)" (?listDevices@ofxFlea3@@QAEXXZ)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class FlyCapture2::Error __thiscall FlyCapture2::BusManager::GetNumOfCameras(unsigned int *)" (__imp_?GetNumOfCameras@BusManager@FlyCapture2@@UAE?AVError@2@PAI@Z) referenced in function "public: void __thiscall ofxFlea3::listDevices(void)" (?listDevices@ofxFlea3@@QAEXXZ)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::Error::Error(void)" (__imp_??0Error@FlyCapture2@@QAE@XZ) referenced in function "public: void __thiscall ofxFlea3::listDevices(void)" (?listDevices@ofxFlea3@@QAEXXZ)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::BusManager::BusManager(void)" (__imp_??0BusManager@FlyCapture2@@QAE@XZ) referenced in function "public: void __thiscall ofxFlea3::listDevices(void)" (?listDevices@ofxFlea3@@QAEXXZ)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class FlyCapture2::Error __thiscall FlyCapture2::Image::Save(char const *,enum FlyCapture2::ImageFileFormat)" (__imp_?Save@Image@FlyCapture2@@UAE?AVError@2@PBDW4ImageFileFormat@2@@Z) referenced in function "public: void __thiscall ofxFlea3::initFlea3(int,int,int,int)" (?initFlea3@ofxFlea3@@QAEXHHHH@Z)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class FlyCapture2::Error __thiscall FlyCapture2::Image::Convert(enum FlyCapture2::PixelFormat,class FlyCapture2::Image *)const " (__imp_?Convert@Image@FlyCapture2@@UBE?AVError@2@W4PixelFormat@2@PAV12@@Z) referenced in function "public: void __thiscall ofxFlea3::initFlea3(int,int,int,int)" (?initFlea3@ofxFlea3@@QAEXHHHH@Z)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class FlyCapture2::Error __thiscall FlyCapture2::Image::ReleaseBuffer(void)" (__imp_?ReleaseBuffer@Image@FlyCapture2@@UAE?AVError@2@XZ) referenced in function "protected: virtual void __thiscall ofxFlea3::getNewFrame(unsigned char *)" (?getNewFrame@ofxFlea3@@MAEXPAE@Z)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual struct FlyCapture2::TimeStamp __thiscall FlyCapture2::Image::GetTimeStamp(void)const " (__imp_?GetTimeStamp@Image@FlyCapture2@@UBE?AUTimeStamp@2@XZ) referenced in function "protected: virtual void __thiscall ofxFlea3::getNewFrame(unsigned char *)" (?getNewFrame@ofxFlea3@@MAEXPAE@Z)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual unsigned char * __thiscall FlyCapture2::Image::GetData(void)" (__imp_?GetData@Image@FlyCapture2@@UAEPAEXZ) referenced in function "protected: virtual void __thiscall ofxFlea3::getNewFrame(unsigned char *)" (?getNewFrame@ofxFlea3@@MAEXPAE@Z)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual unsigned int __thiscall FlyCapture2::Image::GetDataSize(void)const " (__imp_?GetDataSize@Image@FlyCapture2@@UBEIXZ) referenced in function "protected: virtual void __thiscall ofxFlea3::getNewFrame(unsigned char *)" (?getNewFrame@ofxFlea3@@MAEXPAE@Z)
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void __thiscall FlyCapture2::Image::GetDimensions(unsigned int *,unsigned int *,unsigned int *,enum FlyCapture2::PixelFormat *,enum FlyCapture2::BayerTileFormat *)const " (__imp_?GetDimensions@Image@FlyCapture2@@UBEXPAI00PAW4PixelFormat@2@PAW4BayerTileFormat@2@@Z) referenced in function "protected: virtual void __thiscall ofxFlea3::getNewFrame(unsigned char *)" (?getNewFrame@ofxFlea3@@MAEXPAE@Z)
默认情况下,Visual Studio将对成员函数使用__thiscall。由于它编译正确,所以库中的头似乎没有显式声明调用约定。
听起来您需要对库使用C链接。尝试使用包装库标头
extern "C" { }
问题是我链接的是64位版本的外部FlyCapture2库。切换到32位版本解决了这个问题。
相关文章:
- MINGW - 正确运行函数所需的 cdecl
- 如何正确调用 thiscall 函数,并将其作为 mfc 控件
- C#:Cdecl-DllExport,参数中有一个指向类实例的指针
- 使用char**的Pinvoke cdecl约定
- C# GetFunctionPointerForDelegate cdecl instead of stdcall
- 内联组装 - cdecl 并准备堆栈
- cdecl错误:之前应为初始值设定项
- 默认情况下,是使用cdecl+fastcall约定编译的c++成员函数
- Delphi thiscall调用约定
- 如果存在,则使用它/检测C++中当前作用域的调用约定(thiscall vs cdecl)
- CDECL 调用约定 引起奇怪的警告 组装 X86
- AccessViolationException 当 PInvoking C++ DLL (cdecl 调用约定问题?)
- 需要 Cdecl 澄清:什么是"array 5?"
- CDecl清理代码在显式链接的DLL