2013-02-18 45 views
2

我想在Visual Studio 2008中構建一個開源C++項目。我加載解決方案文件並編譯所有內容,但由於未找到某些方法,我收到了一堆鏈接錯誤。使用DUMPBIN.EXE檢查有問題的.lib文件後,我可以看到問題所在:.lib中的方法在它們的簽名中都有__cdecl,而鏈接器正在尋找與__thiscall相同的方法。如何讓VS2008在C++項目中使用__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)" ([email protected]@@[email protected]) referenced in function "public: __thiscall ofxFlea3::ofxFlea3(void)" ([email protected]@[email protected]) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall FlyCapture2::Image::~Image(void)" ([email protected]@@[email protected]) referenced in function "public: __thiscall ofxFlea3::ofxFlea3(void)" ([email protected]@[email protected]) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::Camera::Camera(void)" ([email protected]@@[email protected]) referenced in function "public: __thiscall ofxFlea3::ofxFlea3(void)" ([email protected]@[email protected]) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall FlyCapture2::Camera::~Camera(void)" ([email protected]@@[email protected]) referenced in function "public: __thiscall ofxFlea3::ofxFlea3(void)" ([email protected]@[email protected]) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall FlyCapture2::Error::~Error(void)" ([email protected]@@[email protected]) referenced in function "void __cdecl PrintError(class FlyCapture2::Error)" ([email protected]@[email protected]@@@Z) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual void __thiscall FlyCapture2::Error::PrintErrorTrace(void)const " ([email protected]@[email protected]@UBEXXZ) referenced in function "void __cdecl PrintError(class FlyCapture2::Error)" ([email protected]@[email protected]@@@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 *)" ([email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function "public: void __thiscall ofxFlea3::listDevices(void)" ([email protected]@@QAEXXZ) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall FlyCapture2::BusManager::~BusManager(void)" ([email protected]@@[email protected]) referenced in function "public: void __thiscall ofxFlea3::listDevices(void)" ([email protected]@@QAEXXZ) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::Error::Error(class FlyCapture2::Error const &)" ([email protected]@@[email protected]@@Z) referenced in function "public: void __thiscall ofxFlea3::listDevices(void)" ([email protected]@@QAEXXZ) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class FlyCapture2::Error __thiscall FlyCapture2::BusManager::GetNumOfCameras(unsigned int *)" ([email protected]@[email protected]@[email protected]@[email protected]) referenced in function "public: void __thiscall ofxFlea3::listDevices(void)" ([email protected]@@QAEXXZ) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::Error::Error(void)" ([email protected]@@[email protected]) referenced in function "public: void __thiscall ofxFlea3::listDevices(void)" ([email protected]@@QAEXXZ) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __thiscall FlyCapture2::BusManager::BusManager(void)" ([email protected]@@[email protected]) referenced in function "public: void __thiscall ofxFlea3::listDevices(void)" ([email protected]@@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)" ([email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function "public: void __thiscall ofxFlea3::initFlea3(int,int,int,int)" ([email protected]@@[email protected]) 
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 " ([email protected]@[email protected]@[email protected]@[email protected]@[email protected]@Z) referenced in function "public: void __thiscall ofxFlea3::initFlea3(int,int,int,int)" ([email protected]@@[email protected]) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual class FlyCapture2::Error __thiscall FlyCapture2::Image::ReleaseBuffer(void)" ([email protected]@[email protected]@[email protected]@XZ) referenced in function "protected: virtual void __thiscall ofxFlea3::getNewFrame(unsigned char *)" ([email protected]@@[email protected]) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual struct FlyCapture2::TimeStamp __thiscall FlyCapture2::Image::GetTimeStamp(void)const " ([email protected]@[email protected]@[email protected]@XZ) referenced in function "protected: virtual void __thiscall ofxFlea3::getNewFrame(unsigned char *)" ([email protected]@@[email protected]) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual unsigned char * __thiscall FlyCapture2::Image::GetData(void)" ([email protected]@[email protected]@UAEPAEXZ) referenced in function "protected: virtual void __thiscall ofxFlea3::getNewFrame(unsigned char *)" ([email protected]@@[email protected]) 
1>ofxFlea3.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual unsigned int __thiscall FlyCapture2::Image::GetDataSize(void)const " ([email protected]@[email protected]@UBEIXZ) referenced in function "protected: virtual void __thiscall ofxFlea3::getNewFrame(unsigned char *)" ([email protected]@@[email protected]) 
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 " ([email protected]@[email protected]@[email protected]@[email protected]@@Z) referenced in function "protected: virtual void __thiscall ofxFlea3::getNewFrame(unsigned char *)" ([email protected]@@[email protected]) 
+3

你正在做一些嚴重錯誤的事情,比如#include庫中的.h文件在C++類中。不提供項目名稱或顯示鏈接器錯誤不能幫助我們幫助您。 – 2013-02-18 23:55:13

+0

@HansPassant,10-4,我添加了項目鏈接和鏈接器錯誤。 – Ghopper21 2013-02-19 03:37:56

回答

0

默認情況下,Visual Studio將使用__thiscall成員函數。由於它編譯正確,看起來庫中的頭文件並沒有顯式聲明調用約定。

這聽起來像你需要使用C鏈接庫。嘗試用庫包頭標頭

extern "C" { } 
+0

這樣做會給編譯器帶來如下錯誤:警告C4190:'ForceIPAddressToCamera'指定了C-linkage,但返回與C不兼容的UDT'FlyCapture2 :: Error' – Ghopper21 2013-02-19 03:39:54

0

問題是我連接到64位版本的外部FlyCapture2庫。切換到32位版本解決了這個問題。

相關問題