2013年7月31日 星期三

【OpenCV】Using static library in OpenCV 使用OpenCV的靜態函式庫

在OpenCV資料夾中有靜態的函式庫可以使用。
..\opencv\build\x86\vc10\staticlib

#前面步驟跟使用動態函式庫的方式一樣,只是library換成staticlib底下的.lib
opencv_core244d.lib
opencv_calib3d244d.lib
opencv_contrib244d.lib
opencv_features2d244d.lib
opencv_highgui244d.lib
opencv_imgproc244d.lib
opencv_objdetect244d.lib
此時編譯會出現很多的錯誤資訊,因為OpenCV用到很多第三方函式庫。

warning LNK4098: defaultlib 'MSVCRTD' conflicts with use of other libs; use /NODEFAULTLIB:library
warning LNK4098: defaultlib 'LIBCMTD' conflicts with use of other libs; use /NODEFAULTLIB:library


靜態編譯問題解決流程
【Step 1】
Change Runtime Library <改變Runtime Library>

  • Multi-threaded (/MT) - libcmt.lib
  • Multi-threaded Debug (/MTd) - libcmtd.lib
  • Multi-threaded DLL (/MD) - msvcrt.lib
  • Multi-threaded Debug DLL (/MDd) - msvcrtd.lib

#選擇Multi-threaded Debug (/MTd) - libcmtd.lib


完成後會減少許多錯誤,但還有很多等著我們解決。
error LNK2019: unresolved external symbol _gzputs referenced in function "void __cdecl icvPuts(struct CvFileStorage *,char const *)" (?icvPuts@@YAXPAUCvFileStorage@@PBD@Z)

error LNK2019: unresolved external symbol "public: __thiscall Imf::Chromaticities::Chromaticities(class Imath::Vec2<float> const &,class Imath::Vec2<float> const &,class Imath::Vec2<float> const &,class Imath::Vec2<float> const &)" (??0Chromaticities@Imf@@QAE@ABV?$Vec2@M@Imath@@000@Z) referenced in function "public: __thiscall cv::ExrDecoder::ExrDecoder(void)" (??0ExrDecoder@cv@@QAE@XZ)



【Step 2】
Include 3rd party library <加入第三方程式的函式庫>
IlmImfd.lib
libjasperd.lib
libjpegd.lib
libpngd.lib
libtiffd.lib
zlibd.lib

#加入後錯誤訊息大幅減少
error LNK2019: unresolved external symbol _AVIFileRelease@4 referenced in function "public: virtual void __thiscall CvCaptureAVI_VFW::close(void)" (?close@CvCaptureAVI_VFW@@UAEXXZ)




【Step 3】
Include windows library 加入WINDOWS的函式庫
vfw32.lib<在Microsoft SDKs中找的到>


error LNK2019: unresolved external symbol __imp__CreateToolbarEx@52 referenced in function "int __cdecl icvCreateTrackbar(char const *,char const *,int *,int,void (__cdecl*)(int),void (__cdecl*)(int,void *),void *)" (?icvCreateTrackbar@@YAHPBD0PAHHP6AXH@ZP6AXHPAX@Z3@Z)

只要再加入ComCtl32.lib<在Microsoft SDKs中找的到>

恭喜成功完成編譯

相關文章:OpenCV學習日記

0 意見:

張貼留言