为iOS构建OpenCV

时间:2014-01-31 04:03:03

标签: ios opencv

我正在尝试按照这些http://docs.opencv.org/doc/tutorials/introduction/ios_install/ios_install.html步骤为ios构建opencv并收到以下错误:

-- Setting up iPhoneSimulator toolchain
-- iPhoneSimulator toolchain loaded
-- Setting up iPhoneSimulator toolchain
-- iPhoneSimulator toolchain loaded
-- The CXX compiler identification is GNU 4.2.1
-- The C compiler identification is GNU 4.2.1
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Detected version of GNU GCC: 42 (402)
-- Performing Test HAVE_CXX_FSIGNED_CHAR
-- Performing Test HAVE_CXX_FSIGNED_CHAR - Failed
-- Performing Test HAVE_C_FSIGNED_CHAR
-- Performing Test HAVE_C_FSIGNED_CHAR - Failed
-- Performing Test HAVE_CXX_W
-- Performing Test HAVE_CXX_W - Failed
-- Performing Test HAVE_C_W
-- Performing Test HAVE_C_W - Failed
-- Performing Test HAVE_CXX_WALL
-- Performing Test HAVE_CXX_WALL - Failed
-- Performing Test HAVE_C_WALL
-- Performing Test HAVE_C_WALL - Failed
-- Performing Test HAVE_CXX_WERROR_RETURN_TYPE
-- Performing Test HAVE_CXX_WERROR_RETURN_TYPE - Failed
-- Performing Test HAVE_C_WERROR_RETURN_TYPE
-- Performing Test HAVE_C_WERROR_RETURN_TYPE - Failed
-- Performing Test HAVE_CXX_WERROR_ADDRESS
-- Performing Test HAVE_CXX_WERROR_ADDRESS - Failed
-- Performing Test HAVE_C_WERROR_ADDRESS
-- Performing Test HAVE_C_WERROR_ADDRESS - Failed
-- Performing Test HAVE_CXX_WERROR_SEQUENCE_POINT
-- Performing Test HAVE_CXX_WERROR_SEQUENCE_POINT - Failed
-- Performing Test HAVE_C_WERROR_SEQUENCE_POINT

-- Performing Test HAVE_C_WERROR_SEQUENCE_POINT - Failed

我使用OSX 10.8.5和XCode 5.0.2 我试图明确指定python可执行文件

cmakeargs = ("-GXcode " +
                "-DPYTHON_EXECUTABLE=/usr/bin/python " +
                "-DCMAKE_BUILD_TYPE=Release " +
                "-DCMAKE_TOOLCHAIN_FILE=%s/platforms/ios/cmake/Toolchains/Toolchain-%s_Xcode.cmake " +
                "-DBUILD_opencv_world=ON " +
                "-DCMAKE_INSTALL_PREFIX=install") % (srcroot, target)

但它没有帮助。此外,我试图降级到opencv 2.4 - 它也没有帮助。请指教。

更新 发现第一次失败:

-- Setting up iPhoneOS toolchain
-- iPhoneOS toolchain loaded
-- Detected version of GNU GCC: 42 (402)
-- Looking for linux/videodev.h
-- Looking for linux/videodev.h - not found
-- Looking for linux/videodev2.h
-- Looking for linux/videodev2.h - not found
-- Looking for sys/videoio.h
-- Looking for sys/videoio.h - not found
-- Could NOT find JNI (missing:  JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2)
--
-- General configuration for OpenCV 2.4.8 =====================================
--   Version control:               unknown
--
--   Platform:
--     Host:                        Darwin 12.5.0 i386
--     Target:                      iOS
--     CMake:                       2.8.9
--     CMake generator:             Xcode
--     CMake build tool:            /Applications/CMake 2.8-9.app/Contents/bin/cmakexbuild
--     Xcode:                       5.0.2
--
--   C/C++:
--     Built as dynamic libs?:      NO
--     C++ Compiler:                /usr/bin/g++  (ver 4.2.1)
--     C++ flags (Release):         -stdlib=libc++ -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden -fPIC   -DNDEBUG -O3 -fomit-frame-pointer -ffast-math  -DNDEBUG
--     C++ flags (Debug):           -stdlib=libc++ -headerpad_max_install_names -fvisibility=hidden -fvisibility-inlines-hidden -fPIC   -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/gcc
--     C flags (Release):           -fPIC   -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fPIC   -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):
--     Linker flags (Debug):
--     Precompiled headers:         NO
--
--   OpenCV modules:
--     To be built:                 core flann imgproc highgui features2d calib3d ml nonfree objdetect video contrib legacy photo stitching videostab world
--     Disabled:                    -
--     Disabled by dependency:      -
--     Unavailable:                 androidcamera dynamicuda gpu java ocl python superres ts
--
--   GUI:
--     Cocoa:                       YES
--     OpenGL support:              NO
--
--   Media I/O:
--     ZLib:                        build (ver 1.2.7)
--     JPEG:                        build (ver 62)
--     PNG:                         build (ver 1.5.12)
--     TIFF:                        NO
--     JPEG 2000:                   NO
--     OpenEXR:                     NO
--
--   Video I/O:
--     AVFoundation:                YES
--     QuickTime:                   NO
--     QTKit:                       NO
--     V4L/V4L2:                    NO/NO
--
--   Other third-party libraries:
--     Use IPP:                     NO
--     Use Eigen:                   NO
--     Use TBB:                     NO
--     Use OpenMP:                  NO
--     Use GCD                      YES
--     Use Concurrency              NO
--     Use C=:                      NO
--     Use Cuda:                    NO
--     Use OpenCL:                  NO
--
--   Python:
--     Interpreter:                 /usr/bin/python (ver 2.7.2)
--
--   Java:
--     ant:                         NO
--     JNI:                         JAVA_INCLUDE_PATH-NOTFOUND JAVA_INCLUDE_PATH2-NOTFOUND /System/Library/Frameworks/JavaVM.framework/Headers
--     Java tests:                  NO
--
--   Documentation:
--     Build Documentation:         NO
--     Sphinx:                      NO
--     PdfLaTeX compiler:           NO
--
--   Tests and samples:
--     Tests:                       NO
--     Performance tests:           NO
--     C/C++ Examples:              NO
--
--   Install path:                  /Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/install
--
--   cvconfig.h is in:              /Users/podlipensky/Sites/ios/build/iPhoneOS-arm64
-- -----------------------------------------------------------------
--
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/podlipensky/Sites/ios/build/iPhoneOS-arm64
User defaults from command line:
    IDEBuildOperationMaxNumberOfConcurrentCompileTasks = 8

Build settings from command line:
    ARCHS = arm64
    IPHONEOS_DEPLOYMENT_TARGET = 6.0
    SDKROOT = iphoneos7.0

Build Preparation
Build task concurrency set to 8 via user default IDEBuildOperationMaxNumberOfConcurrentCompileTasks

=== BUILD TARGET zlib OF PROJECT OpenCV WITH CONFIGURATION Release ===

Check dependencies

CompileC /Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib/OpenCV.build/Release-iphoneos/zlib.build/Objects-normal/arm64/gzwrite.o 3rdparty/zlib/gzwrite.c normal arm64 c com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/podlipensky/Sites/opencv
    setenv LANG en_US.US-ASCII
    setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Users/podlipensky/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/git/bin:/opt/local/bin:/Users/podlipensky/Downloads/arcanist/bin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c -arch arm64 -fmessage-length=118 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -Wno-trigraphs -fpascal-strings -O3 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -DCMAKE_INTDIR=\"Release-iphoneos\" -DNO_FSEEKO -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -fstrict-aliasing -Wdeprecated-declarations -Wno-sign-conversion -miphoneos-version-min=6.0 -I/Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/lib/Release/include -I/Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib -I/Users/podlipensky/Sites/opencv/3rdparty/zlib -I/Users/podlipensky/Sites/ios/build/iPhoneOS-arm64 -I/Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib/OpenCV.build/Release-iphoneos/zlib.build/DerivedSources/arm64 -I/Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib/OpenCV.build/Release-iphoneos/zlib.build/DerivedSources -Wmost -Wno-four-char-constants -Wno-unknown-pragmas -F/Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/lib/Release -fPIC -fPIC -DNDEBUG -DNDEBUG -MMD -MT dependencies -MF /Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib/OpenCV.build/Release-iphoneos/zlib.build/Objects-normal/arm64/gzwrite.d --serialize-diagnostics /Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib/OpenCV.build/Release-iphoneos/zlib.build/Objects-normal/arm64/gzwrite.dia -c /Users/podlipensky/Sites/opencv/3rdparty/zlib/gzwrite.c -o /Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib/OpenCV.build/Release-iphoneos/zlib.build/Objects-normal/arm64/gzwrite.o
/Users/podlipensky/Sites/opencv/3rdparty/zlib/gzwrite.c:84:15: error: implicit declaration of function 'write' is
      invalid in C99 [-Werror,-Wimplicit-function-declaration]
        got = write(state->fd, strm->next_in, strm->avail_in);
              ^
/Users/podlipensky/Sites/opencv/3rdparty/zlib/gzwrite.c:84:15: note: did you mean 'fwrite'?
        got = write(state->fd, strm->next_in, strm->avail_in);
              ^~~~~
              fwrite
In file included from /Users/podlipensky/Sites/opencv/3rdparty/zlib/gzwrite.c:6:
In file included from /Users/podlipensky/Sites/opencv/3rdparty/zlib/gzguts.h:21:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/stdio.h:252:9: note:
      'fwrite' declared here
size_t   fwrite(const void * __restrict, size_t, size_t, FILE * __restrict) __DARWIN_ALIAS(fwrite);
         ^
/Users/podlipensky/Sites/opencv/3rdparty/zlib/gzwrite.c:561:9: error: implicit declaration of function 'close' is
      invalid in C99 [-Werror,-Wimplicit-function-declaration]
    if (close(state->fd) == -1)
        ^
2 errors generated.

CompileC /Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib/OpenCV.build/Release-iphoneos/zlib.build/Objects-normal/arm64/gzread.o 3rdparty/zlib/gzread.c normal arm64 c com.apple.compilers.llvm.clang.1_0.compiler
    cd /Users/podlipensky/Sites/opencv
    setenv LANG en_US.US-ASCII
    setenv PATH "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin:/Applications/Xcode.app/Contents/Developer/usr/bin:/Users/podlipensky/bin:/usr/local/bin:/usr/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/local/git/bin:/opt/local/bin:/Users/podlipensky/Downloads/arcanist/bin"
    /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -x c -arch arm64 -fmessage-length=118 -fdiagnostics-show-note-include-stack -fmacro-backtrace-limit=0 -fcolor-diagnostics -Wno-trigraphs -fpascal-strings -O3 -Wno-missing-field-initializers -Wno-missing-prototypes -Wno-return-type -Wno-missing-braces -Wparentheses -Wswitch -Wno-unused-function -Wno-unused-label -Wno-unused-parameter -Wno-unused-variable -Wunused-value -Wno-empty-body -Wno-uninitialized -Wno-unknown-pragmas -Wno-shadow -Wno-four-char-constants -Wno-conversion -Wno-constant-conversion -Wno-int-conversion -Wno-bool-conversion -Wno-enum-conversion -Wshorten-64-to-32 -Wpointer-sign -Wno-newline-eof -DCMAKE_INTDIR=\"Release-iphoneos\" -DNO_FSEEKO -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk -fstrict-aliasing -Wdeprecated-declarations -Wno-sign-conversion -miphoneos-version-min=6.0 -I/Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/lib/Release/include -I/Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib -I/Users/podlipensky/Sites/opencv/3rdparty/zlib -I/Users/podlipensky/Sites/ios/build/iPhoneOS-arm64 -I/Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib/OpenCV.build/Release-iphoneos/zlib.build/DerivedSources/arm64 -I/Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib/OpenCV.build/Release-iphoneos/zlib.build/DerivedSources -Wmost -Wno-four-char-constants -Wno-unknown-pragmas -F/Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/lib/Release -fPIC -fPIC -DNDEBUG -DNDEBUG -MMD -MT dependencies -MF /Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib/OpenCV.build/Release-iphoneos/zlib.build/Objects-normal/arm64/gzread.d --serialize-diagnostics /Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib/OpenCV.build/Release-iphoneos/zlib.build/Objects-normal/arm64/gzread.dia -c /Users/podlipensky/Sites/opencv/3rdparty/zlib/gzread.c -o /Users/podlipensky/Sites/ios/build/iPhoneOS-arm64/3rdparty/zlib/OpenCV.build/Release-iphoneos/zlib.build/Objects-normal/arm64/gzread.o
/Users/podlipensky/Sites/opencv/3rdparty/zlib/gzread.c:30:15: error: implicit declaration of function 'read' is
      invalid in C99 [-Werror,-Wimplicit-function-declaration]
        ret = read(state->fd, buf + *have, len - *have);
              ^
/Users/podlipensky/Sites/opencv/3rdparty/zlib/gzread.c:30:15: note: did you mean 'fread'?
        ret = read(state->fd, buf + *have, len - *have);
              ^~~~
              fread
In file included from /Users/podlipensky/Sites/opencv/3rdparty/zlib/gzread.c:6:
In file included from /Users/podlipensky/Sites/opencv/3rdparty/zlib/gzguts.h:21:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.0.sdk/usr/include/stdio.h:245:9: note:
      'fread' declared here
size_t   fread(void * __restrict, size_t, size_t, FILE * __restrict);
         ^
/Users/podlipensky/Sites/opencv/3rdparty/zlib/gzread.c:586:11: error: implicit declaration of function 'close' is
      invalid in C99 [-Werror,-Wimplicit-function-declaration]
    ret = close(state->fd);

1 个答案:

答案 0 :(得分:6)

最终,我设法通过将这些行添加到buld_framework.py第40行来解决问题:

"-DPYTHON_EXECUTABLE=/usr/bin/python " +
"-DCMAKE_C_FLAGS=\"-Wno-implicit-function-declaration\" " +