openCV mingw+cmake編譯的bug/error筆記

使用cmake生成openCV3.1.0 makefile文件,在mingw下編譯openCV。

1.openCV的build和源碼目錄,不能存在中文路徑,否則報以下錯誤:

mingw32-make[2]: *** No rule to make target 'J://opencv-3.1.0/3rdparty/zlib/adler32.c', needed by '3rdparty/zlib/CMakeFiles/zlib.dir/adler32.c.obj'.  Stop.
CMakeFiles\Makefile2:252: recipe for target '3rdparty/zlib/CMakeFiles/zlib.dir/all' failed
mingw32-make[1]: *** [3rdparty/zlib/CMakeFiles/zlib.dir/all] Error 2
Makefile:161: recipe for target 'all' failed
mingw32-make: *** [all] Error 2


2.使用cmake發佈makefile的時候,請禁用BUILD_TESTS,否則將在42%左右報以下錯誤:

G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp: In constructor 'testing::internal::Mutex::Mutex()':
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8829:45: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in initialization
       critical_section_(new CRITICAL_SECTION) {
                                             ^
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8830:48: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
   ::InitializeCriticalSection(critical_section_);
                                                ^
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp: In destructor 'testing::internal::Mutex::~Mutex()':
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8840:46: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'PCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void DeleteCriticalSection(PCRITICAL_SECTION)'
     ::DeleteCriticalSection(critical_section_);
                                              ^
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Lock()':
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8848:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void EnterCriticalSection(LPCRITICAL_SECTION)'
   ::EnterCriticalSection(critical_section_);
                                           ^
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Unlock()':
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8858:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void LeaveCriticalSection(LPCRITICAL_SECTION)'
   ::LeaveCriticalSection(critical_section_);
                                           ^
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::ThreadSafeLazyInit()':
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8879:33: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in assignment
         critical_section_ = new CRITICAL_SECTION;
                                 ^~~~~~~~~~~~~~~~
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8880:54: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
         ::InitializeCriticalSection(critical_section_);
                                                      ^
modules\ts\CMakeFiles\opencv_ts.dir\build.make:237: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj' failed
mingw32-make[2]: *** [modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj] Error 1
CMakeFiles\Makefile2:5379: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/all' failed
mingw32-make[1]: *** [modules/ts/CMakeFiles/opencv_ts.dir/all] Error 2
Makefile:161: recipe for target 'all' failed
mingw32-make: *** [all] Error 2

3.opencv3.2.0 mingw編譯,在54%左右報以下錯誤:

G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp: In constructor 'testing::internal::Mutex::Mutex()':
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8829:45: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in initialization
       critical_section_(new CRITICAL_SECTION) {
                                             ^
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8830:48: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
   ::InitializeCriticalSection(critical_section_);
                                                ^
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp: In destructor 'testing::internal::Mutex::~Mutex()':
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8840:46: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'PCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void DeleteCriticalSection(PCRITICAL_SECTION)'
     ::DeleteCriticalSection(critical_section_);
                                              ^
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Lock()':
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8848:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void EnterCriticalSection(LPCRITICAL_SECTION)'
   ::EnterCriticalSection(critical_section_);
                                           ^
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::Unlock()':
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8858:43: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void LeaveCriticalSection(LPCRITICAL_SECTION)'
   ::LeaveCriticalSection(critical_section_);
                                           ^
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp: In member function 'void testing::internal::Mutex::ThreadSafeLazyInit()':
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8879:33: error: cannot convert 'CRITICAL_SECTION* {aka _CRITICAL_SECTION*}' to '_RTL_CRITICAL_SECTION*' in assignment
         critical_section_ = new CRITICAL_SECTION;
                                 ^~~~~~~~~~~~~~~~
G:\Coding\MinGW\msys\1.0\home\Administrator\opencv-3.2.0\modules\ts\src\ts_gtest.cpp:8880:54: error: cannot convert '_RTL_CRITICAL_SECTION*' to 'LPCRITICAL_SECTION {aka _CRITICAL_SECTION*}' for argument '1' to 'void InitializeCriticalSection(LPCRITICAL_SECTION)'
         ::InitializeCriticalSection(critical_section_);

                                                      ^

modules\ts\CMakeFiles\opencv_ts.dir\build.make:237: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj' failed
mingw32-make[3]: *** [modules/ts/CMakeFiles/opencv_ts.dir/src/ts_gtest.cpp.obj] Error 1
CMakeFiles\Makefile2:3919: recipe for target 'modules/ts/CMakeFiles/opencv_ts.dir/all' failed
mingw32-make[2]: *** [modules/ts/CMakeFiles/opencv_ts.dir/all] Error 2
Makefile:161: recipe for target 'all' failed
mingw32-make[1]: *** [all] Error 2

參考國外給出的修改.h文件,增加mingw目標的定義:

https://stackoverflow.com/questions/41930349/opencv-installation-error-while-mingw32-make-on-windows

Edit "ts_gtest.h" which is inside "opencv\sources\modules\ts\include\opencv2\ts\"

Replace this line (probably line 723) 


    // assuming CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
    // This assumption is verified by
    // WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION.
    struct _RTL_CRITICAL_SECTION;


with



    #if GTEST_OS_WINDOWS_MINGW
        // MinGW defined _CRITICAL_SECTION and _RTL_CRITICAL_SECTION as two
        // separate (equivalent) structs, instead of using typedef
        typedef struct _CRITICAL_SECTION GTEST_CRITICAL_SECTION;
    #else
        // Assume CRITICAL_SECTION is a typedef of _RTL_CRITICAL_SECTION.
        // This assumption is verified by
        // WindowsTypesTest.CRITICAL_SECTIONIs_RTL_CRITICAL_SECTION
        typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
    #endif


Replace this line (probably on line 3060 before your edit - line number would have changed as you modified first part)


    _RTL_CRITICAL_SECTION* critical_section_;


with



    GTEST_CRITICAL_SECTION* critical_section_;


These two changes should fix your above error.


4.Ubuntu14下編譯FFmpeg外加庫與filter報錯:

/usr/bin/ld: /usr/local/lib//libTransform360.a(VideoFrameTransformHandler.cpp.o): relocation R_X86_64_32 against `.bss' can not be used when making a shared object; recompile with -fPIC
/usr/local/lib//libTransform360.a: 無法添加符號: 錯誤的值

上述錯誤提示和原來的沒有添加“-fPIC”生成的“*.o”文件生成動態庫出現的錯誤相同,而且也給給出瞭解決方法,靜態庫的生成重新使用“-fPIC”進行編譯。

[billing_dx@bmcs1]:/account/work/ymm/test/library/nest_call>g++ -fPIC -c showcoor.cpp  
[billing_dx@bmcs1]:/account/work/ymm/test/library/nest_call>ar -cr libshowcoor.a showcoor.o  
[billing_dx@bmcs1]:/account/work/ymm/test/library/nest_call>g++ -fPIC -c showpoint.cpp            
[billing_dx@bmcs1]:/account/work/ymm/test/library/nest_call>g++ -shared -fPIC -o libshowpoint.so showpoint.o -L./ -lshowcoor  
[billing_dx@bmcs1]:/account/work/ymm/test/library/nest_call>ls *.so  
libshowpoint.so 


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章