opencv / opencv

Open Source Computer Vision Library
https://opencv.org
Apache License 2.0
79.37k stars 55.86k forks source link

Issues Compiling opencv3.2 with CUDA on Mac OS 10.12 #8638

Open changkaizhao opened 7 years ago

changkaizhao commented 7 years ago

My env and lib versions:

Mac OS 10.12, opencv 3.2(download from here ) cuda8.0 , qt5 installed via brew, Xcode8 & Xcode7(with CLT to compile cuda stuff)

I intended to install opencv3.2 by compiling source code.

cmake settings like below:

build without opencv_highgui & opencv_videoio(if these settings turned on, compiling would fail)

TURN OFF WITH_AVFOUNDATION,WITH_1394,WITH_QT ,WITH_QTKIT,WITH_QUICKTIME,WITH_TBB,WITH_IPP,WITH_GSTREAMER ...

TURN ON WITH_CUDA,WITH_EIGEN,WITH_JASPER,WITH_JPEG,WITH_LAPACK,WITH_OPENEXR,WITH_PNG,WITH_PTHREADS_PF,WITH_TIFF

with the setting as above compiled successfully!

but without opencv_highgui & opencv_videoio how can I show a image or read camera frames?

if I build opencv_videoio, and select any one of WITH_AVFOUNDATION, WITH_QTKIT,WITH_QUICKTIME will not successfully compiling.

errors like: (this error generate with quicktime FLAG)

 ~/openCV/opencv-3.2.0/modules/videoio/src/cap_qt.cpp:75:5: error: unknown type name 'Movie'
    Movie      myMovie;            // movie handle
    ^

~/openCV/opencv-3.2.0/modules/videoio/src/cap_qt.cpp:103:9: error: use of undeclared identifier 'EnterMovies'
        EnterMovies();
        ^

~/openCV/opencv-3.2.0/modules/videoio/src/cap_qt.cpp:142:5: error: use of undeclared identifier 'ClearMoviesStickyError'
    ClearMoviesStickyError ();
    ^
StevenPuttemans commented 7 years ago

can you run cmake-gui and verify if CMAKE is able to find your QT installation. My guess that is the issue and you probably need to built Qt from sources yourself first.

changkaizhao commented 7 years ago

@StevenPuttemans
I deselect with_Qtkit & with_QUICKTIME, select WITH_AVFOUNDATION the CMAKE configuration like this:

found Intel IPP (ICV version): 2017.0.2 [2017.0.2]
at: ~/openCV/opencv-master/build_static/3rdparty/ippicv/ippicv_mac
found Intel IPP IW binaries: 2017.0.2
at: ~/openCV/opencv-master/build_static/3rdparty/ippicv/ippicv_mac/../ippiw_mac/
CUDA detected: 8.0
CUDA NVCC target flags: -gencode;arch=compute_20,code=sm_20;-gencode;arch=compute_30,code=sm_30;-gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_52,code=sm_52;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_61,code=sm_61;-D_FORCE_INLINES
LAPACK(LAPACK/Apple): LAPACK_LIBRARIES: /System/Library/Frameworks/Accelerate.framework;/System/Library/Frameworks/Accelerate.framework
LAPACK(LAPACK/Apple): Support is enabled.

General configuration for OpenCV 3.2.0-dev =====================================
  Version control:               unknown

  Platform:
    Timestamp:                   2017-04-24T14:48:00Z
    Host:                        Darwin 16.5.0 x86_64
    CMake:                       3.0.1
    CMake generator:             Unix Makefiles
    CMake build tool:            /usr/bin/make
    Configuration:               Release

  CPU/HW features:
    Baseline:                    SSE SSE2 SSE3 SSSE3
      requested:                 SSSE3
    Dispatched code generation:  SSE4_1 FP16 AVX AVX2
      requested:                 SSE4_1 AVX FP16 AVX2
      SSE4_1 (0 files):          + SSE4_1
      FP16 (0 files):            + SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (1 files):             + SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (1 files):            + SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2

  C/C++:
    Built as dynamic libs?:      YES
    C++ Compiler:                /usr/bin/c++  (ver 7.3.0.7030029)
    C++ flags (Release):         -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -fno-omit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -mssse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C++ flags (Debug):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -fno-omit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -mssse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    C Compiler:                  /usr/bin/cc
    C flags (Release):           -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -fno-omit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -mssse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
    C flags (Debug):             -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-unnamed-type-template-args -Wno-comment -fdiagnostics-show-option -Wno-long-long -Qunused-arguments -Wno-semicolon-before-method-body -fno-omit-frame-pointer -ffunction-sections  -msse -msse2 -msse3 -mssse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
    Linker flags (Release):      
    Linker flags (Debug):        
    ccache:                      NO
    Precompiled headers:         NO
    Extra dependencies:          /System/Library/Frameworks/Accelerate.framework Qt5::Core Qt5::Gui Qt5::Widgets Qt5::Test Qt5::Concurrent -framework Cocoa -framework Accelerate -framework AVFoundation -framework CoreGraphics -framework CoreMedia -framework CoreVideo -framework QuartzCore /Users/zhaochangkai/Books/openCV/opencv-master/build_static/3rdparty/ippicv/ippicv_mac/../ippiw_mac//lib/intel64/libipp_iw.a cudart nppc nppi npps cufft -L/usr/local/cuda/lib
    3rdparty dependencies:       libjpeg libpng libtiff libjasper IlmImf zlib

  OpenCV modules:
    To be built:                 cudev core cudaarithm flann imgproc ml objdetect video cudabgsegm cudafilters cudaimgproc cudawarping imgcodecs photo shape videoio highgui ts features2d calib3d cudafeatures2d cudalegacy cudaobjdetect cudaoptflow cudastereo stitching superres videostab python2
    Disabled:                    world
    Disabled by dependency:      -
    Unavailable:                 cudacodec java python3 viz

  GUI: 
    QT 5.x:                      YES (ver 5.8.0)
    QT OpenGL support:           NO
    OpenGL support:              NO
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.8)
    JPEG:                        build (ver 90)
    WEBP:                        NO
    PNG:                         build (ver 1.6.24)
    TIFF:                        build (ver 42 - 4.0.2)
    JPEG 2000:                   build (ver 1.900.1)
    OpenEXR:                     build (ver 1.7.1)
    GDAL:                        NO
    GDCM:                        NO

  Video I/O:
    DC1394 1.x:                  NO
    DC1394 2.x:                  NO
    FFMPEG:                      NO
      avcodec:                   NO
      avformat:                  NO
      avutil:                    NO
      swscale:                   NO
      avresample:                NO
    GStreamer:                   NO
    OpenNI:                      NO
    OpenNI PrimeSensor Modules:  NO
    OpenNI2:                     NO
    PvAPI:                       NO
    GigEVisionSDK:               NO
    Aravis SDK:                  NO
    AVFoundation:                YES
    V4L/V4L2:                    NO/NO
    XIMEA:                       NO
    gPhoto2:                     NO

  Parallel framework:            GCD

  Other third-party libraries:
    Use Intel IPP:               2017.0.2 [2017.0.2]
               at:              ~/openCV/opencv-master/build_static/3rdparty/ippicv/ippicv_mac
    Use Intel IPP IW:            prebuilt binaries (2017.0.2)
    Use Intel IPP Async:         NO
    Use VA:                      NO
    Use Intel VA-API/OpenCL:     NO
    Use Lapack:                  YES (/System/Library/Frameworks/Accelerate.framework /System/Library/Frameworks/Accelerate.framework)
    Use Eigen:                   YES (ver 3.3.3)
    Use Cuda:                    YES (ver 8.0)
    Use OpenCL:                  NO
    Use OpenVX:                  NO
    Use custom HAL:              NO

  NVIDIA CUDA
    Use CUFFT:                   YES
    Use CUBLAS:                  NO
    USE NVCUVID:                 NO
    NVIDIA GPU arch:             20 30 35 37 50 52 60 61
    NVIDIA PTX archs:
    Use fast math:               NO

  Python 2:
    Interpreter:                 /usr/bin/python2.7 (ver 2.7.10)
    Libraries:                   /usr/lib/libpython2.7.dylib (ver 2.7.10)
    numpy:                       /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy/core/include (ver 1.8.0rc1)
    packages path:               lib/python2.7/site-packages

  Python 3:
    Interpreter:                 /usr/local/bin/python3 (ver 3.5)

  Python (for build):            /usr/bin/python2.7

  Java:
    ant:                         NO
    JNI:                         /System/Library/Frameworks/JavaVM.framework/Headers /System/Library/Frameworks/JavaVM.framework/Headers /System/Library/Frameworks/JavaVM.framework/Headers
    Java wrappers:               NO
    Java tests:                  NO

  Matlab:                        NO

  Documentation:
    Doxygen:                     /Applications/Doxygen.app/Contents/Resources/doxygen (ver 1.8.6)

  Tests and samples:
    Tests:                       NO
    Performance tests:           YES
    C/C++ Examples:              NO

  Install path:                  /usr/local

  cvconfig.h is in:             ~/openCV/opencv-master/build_static
-----------------------------------------------------------------

but it always generates errors as below:

[ 47%] Building CXX object modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_avfoundation_mac.mm.o
In file included from ~/openCV/opencv-master/modules/videoio/src/cap_avfoundation_mac.mm:46:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVFoundation.h:22:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVAnimation.h:11:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:10:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/NSArray.h:5:
/System/Library/Frameworks/Foundation.framework/Headers/NSObject.h:44:12: error: unknown property attribute 'class'
@property (class, readonly) BOOL supportsSecureCoding;
           ^
In file included from ~/openCV/opencv-master/modules/videoio/src/cap_avfoundation_mac.mm:46:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVFoundation.h:22:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVAnimation.h:11:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:12:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/NSBundle.h:6:
/System/Library/Frameworks/Foundation.framework/Headers/NSString.h:262:12: error: unknown property attribute 'class'
@property (class, readonly) const NSStringEncoding *availableStringEncodings;
           ^
/System/Library/Frameworks/Foundation.framework/Headers/NSString.h:269:12: error: unknown property attribute 'class'
@property (class, readonly) NSStringEncoding defaultCStringEncoding;    // Should be rarely used
           ^
In file included from ~/openCV/opencv-master/modules/videoio/src/cap_avfoundation_mac.mm:46:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVFoundation.h:22:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVAnimation.h:11:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:12:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/NSBundle.h:11:
/System/Library/Frameworks/Foundation.framework/Headers/NSNotification.h:45:12: error: unknown property attribute 'class'
@property (class, readonly, strong) NSNotificationCenter *defaultCenter;
           ^
In file included from ~/openCV/opencv-master/modules/videoio/src/cap_avfoundation_mac.mm:46:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVFoundation.h:22:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVAnimation.h:11:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:12:
/System/Library/Frameworks/Foundation.framework/Headers/NSBundle.h:33:12: error: unknown property attribute 'class'
@property (class, readonly, strong) NSBundle *mainBundle;
           ^
/System/Library/Frameworks/Foundation.framework/Headers/NSBundle.h:46:12: error: unknown property attribute 'class'
@property (class, readonly, copy) NSArray<NSBundle *> *allBundles;
           ^
/System/Library/Frameworks/Foundation.framework/Headers/NSBundle.h:47:12: error: unknown property attribute 'class'
@property (class, readonly, copy) NSArray<NSBundle *> *allFrameworks;
           ^
In file included from ~/openCV/opencv-master/modules/videoio/src/cap_avfoundation_mac.mm:46:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVFoundation.h:22:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVAnimation.h:11:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:14:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/NSCalendar.h:7:
/System/Library/Frameworks/Foundation.framework/Headers/NSDate.h:46:12: error: unknown property attribute 'class'
@property (class, readonly) NSTimeInterval timeIntervalSinceReferenceDate;
           ^
/System/Library/Frameworks/Foundation.framework/Headers/NSDate.h:60:12: error: unknown property attribute 'class'
@property (class, readonly, copy) NSDate *distantFuture;
           ^
/System/Library/Frameworks/Foundation.framework/Headers/NSDate.h:61:12: error: unknown property attribute 'class'
@property (class, readonly, copy) NSDate *distantPast;
           ^
In file included from ~/openCV/opencv-master/modules/videoio/src/cap_avfoundation_mac.mm:46:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVFoundation.h:22:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVAnimation.h:11:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:14:
/System/Library/Frameworks/Foundation.framework/Headers/NSCalendar.h:108:12: error: unknown property attribute 'class'
@property (class, readonly, copy) NSCalendar *currentCalendar;                                  // user's preferred calendar
           ^
/System/Library/Frameworks/Foundation.framework/Headers/NSCalendar.h:109:12: error: unknown property attribute 'class'
@property (class, readonly, strong) NSCalendar *autoupdatingCurrentCalendar NS_AVAILABLE(10_5, 2_0); // tracks changes to user's preferred calendar identifier
           ^
In file included from ~/openCV/opencv-master/modules/videoio/src/cap_avfoundation_mac.mm:46:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVFoundation.h:22:
In file included from /System/Library/Frameworks/AVFoundation.framework/Headers/AVAnimation.h:11:
In file included from /System/Library/Frameworks/Foundation.framework/Headers/Foundation.h:15:
/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h:21:22: error: unknown property attribute 'class'
@property (readonly, class, copy) NSCharacterSet *controlCharacterSet;
                     ^
/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h:22:22: error: unknown property attribute 'class'
@property (readonly, class, copy) NSCharacterSet *whitespaceCharacterSet;
                     ^
/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h:23:22: error: unknown property attribute 'class'
@property (readonly, class, copy) NSCharacterSet *whitespaceAndNewlineCharacterSet;
                     ^
/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h:24:22: error: unknown property attribute 'class'
@property (readonly, class, copy) NSCharacterSet *decimalDigitCharacterSet;
                     ^
/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h:25:22: error: unknown property attribute 'class'
@property (readonly, class, copy) NSCharacterSet *letterCharacterSet;
                     ^
/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h:26:22: error: unknown property attribute 'class'
@property (readonly, class, copy) NSCharacterSet *lowercaseLetterCharacterSet;
                     ^
/System/Library/Frameworks/Foundation.framework/Headers/NSCharacterSet.h:27:22: error: unknown property attribute 'class'
@property (readonly, class, copy) NSCharacterSet *uppercaseLetterCharacterSet;
                     ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
make[2]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/src/cap_avfoundation_mac.mm.o] Error 1
make[1]: *** [modules/videoio/CMakeFiles/opencv_videoio.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
changkaizhao commented 7 years ago

I may know the reason why it failed. I have to use Xcode8 to compile opencv that won't generate system lib errors. but I am not able to compile with cuda8(it only supports CLT 7.3). SO BAD! I have to wait NVIDIA upgrade its CUDA8 to support latest Xcode8.3.2!

changkaizhao commented 7 years ago

I just read cuda8 doc

Table 1. Mac Operating System Support in CUDA 8.0.61 Toolchain Mac OSX Version (native x86_64) Xcode Apple LLVM 10.11 10.12 7.2 7.0.3 YES NO 8.2 8.0.0 NO YES

the latest cuda8.0.61 already support xcode8.2, so i just downgrade xcode8.3.2 to 8.2 to fix the problem!

StevenPuttemans commented 7 years ago

Ok some remarks on your CMAKE output: QT 5.x: YES (ver 5.8.0) --> so the WITH_QT flag is still set to true. I guess that is not what you wanted. Furthermore the errors seem to be due to your AVfoundation version not being the most recent and thus not supporting Xcode8.

StevenPuttemans commented 7 years ago

Reading your last comment, this topic can clearly be closed, since it is due to NVIDIA and not due to OpenCV.

changkaizhao commented 7 years ago

@StevenPuttemans after tried Xcode8.2, still have problems with compiling. so upset!
for now ,I have XCODE8.2 (CLT 8.2) cuda8.0.61 installed . MacOS 10.12.
I switched CLT to 8.2, it has following errors:

[ 22%] Building NVCC (Device) object modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o
/usr/local/cuda/include/host_defines.h(230): error: expected a ";"
...

/Applications/Xcode82.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../include/c++/v1/cstddef(97): error: identifier "nullptr" is undefined
...
Error limit reached.
100 errors detected in the compilation of "/var/folders/8m/sf0dl8513ydfphq7g4sws_0c0000gn/T//tmpxft_00014330_00000000-19_gpu_mat.compute_61.cpp1.ii".
Compilation terminated.
CMake Error at cuda_compile_generated_gpu_mat.cu.o.cmake:264 (message):
  Error generating file
  ~/openCV/opencv-master/build_dynamic/modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o

make[2]: *** [modules/core/CMakeFiles/cuda_compile.dir/src/cuda/./cuda_compile_generated_gpu_mat.cu.o] Error 1
make[1]: *** [modules/core/CMakeFiles/opencv_core.dir/all] Error 2
make: *** [all] Error 2

btw I successfully compiled torch7 with cuda8 and xcode8.2, but it fails to opencv! so weird!