c++ - 如何让 VS2008 在 C++ 项目中使用 __cdecl 而不是 __thiscall?

标签 c++ visual-studio-2008 linker

我正在尝试在 Visual Studio 2008 中构建一个开源 C++ 项目。我加载了解决方案文件并编译了所有内容,但由于未找到某些方法,我遇到了一堆链接错误。使用 DUMPBIN.EXE 检查有问题的 .lib 文件后,我可以看出问题所在:.lib 中的方法的签名中都有 __cdecl,而链接器正在寻找等效项用 __thiscall 代替的方法。

如何让 VS 2008 改为使用 __cdecl

注意:项目是a fork of 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。由于它编译正确,您的库中的 header 似乎没有明确声明调用约定。

听起来您需要对库使用 C 链接。尝试用

包装库 header
extern "C" { }

关于c++ - 如何让 VS2008 在 C++ 项目中使用 __cdecl 而不是 __thiscall?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14946921/

相关文章:

windows - 使用 DEF 文件而不是 LIB 文件链接到 DLL?

c++ - 如何访问 HashMap 中键的值

c++ - 类连续数据

c++ - 如何在默认模板参数中引用自身类型?

c++ - Visual Studio 08鼠标悬停时的函数信息显示

c# - 使用 Visual Studio 速成版连接到 SQL Server

visual-studio-2008 - Windows 7 x64 上的 WCF 调试

c++ - 给定一个整数 n,返回它可以表示为 1 和 2 之和的方式的数量

Haskell 在 Ubuntu 上与动态库链接

linux - makefile 中的 -I 和 -L 有什么区别?