Cmake无法在构建OpenCv时识别Java

时间:2018-09-24 10:17:44

标签: java c++ opencv cmake opencv3.0

我正在尝试在Khadas Vim2上构建 OpenCv ,该产品已预先安装了使用Make的基于 arm 64位的cpu架构的Ubuntu Mate。 。但是,CMake无法识别Java(where i already have both oracle-jdk-1.8 and openjdk-1.8)。我尝试重新安装Apache Ant,并通过以下方式将JAVA_HOMEANT_HOME导出到PATH中:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-arm64
export PATH=$JAVA_HOME/bin:$PATH
export ANT_HOME=/usr/local/ant
export PATH=$ANT_HOME/bin:$PATH

我还尝试将工具链文件中的GCC和G ++编译器设置为:

set( CMAKE_SYSTEM_PROCESSOR arm )
set( CMAKE_C_COMPILER arm-linux-gnueabi-gcc )
set( CMAKE_CXX_COMPILER arm-linux-gnueabi-g++ )

    if(COMMAND toolchain_save_config)
      return() # prevent recursive call
    endif()

    set(CMAKE_SYSTEM_NAME Linux)
    set(CMAKE_SYSTEM_VERSION 1)
    if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
      set(CMAKE_SYSTEM_PROCESSOR arm)
    else()
      #message("CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
    endif()

    include("${CMAKE_CURRENT_LIST_DIR}/gnu.toolchain.cmake")

    if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm AND NOT ARM_IGNORE_FP)
      set(FLOAT_ABI_SUFFIX "")
      if(NOT SOFTFP)
        set(FLOAT_ABI_SUFFIX "hf")
      endif()
    endif()

    if(NOT "x${GCC_COMPILER_VERSION}" STREQUAL "x")
      set(__GCC_VER_SUFFIX "-${GCC_COMPILER_VERSION}")
    endif()

    if(NOT DEFINED CMAKE_C_COMPILER)
      find_program(CMAKE_C_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-gcc${__GCC_VER_SUFFIX})
    else()
      #message(WARNING "CMAKE_C_COMPILER=${CMAKE_C_COMPILER} is defined")
    endif()
    if(NOT DEFINED CMAKE_CXX_COMPILER)
      find_program(CMAKE_CXX_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-g++${__GCC_VER_SUFFIX})
    else()
      #message(WARNING "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} is defined")
    endif()
    if(NOT DEFINED CMAKE_LINKER)
      find_program(CMAKE_LINKER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld)
    else()
      #message(WARNING "CMAKE_LINKER=${CMAKE_LINKER} is defined")
    endif()
    if(NOT DEFINED CMAKE_AR)
      find_program(CMAKE_AR NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar)
    else()
      #message(WARNING "CMAKE_AR=${CMAKE_AR} is defined")
    endif()

    if(NOT DEFINED ARM_LINUX_SYSROOT AND DEFINED GNU_MACHINE)
      set(ARM_LINUX_SYSROOT /usr/${GNU_MACHINE}${FLOAT_ABI_SUFFIX})
    endif()

    if(NOT DEFINED CMAKE_CXX_FLAGS)
      set(CMAKE_CXX_FLAGS           "" CACHE INTERNAL "")
      set(CMAKE_C_FLAGS             "" CACHE INTERNAL "")
      set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")
      set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")
      set(CMAKE_EXE_LINKER_FLAGS    "" CACHE INTERNAL "")

      set(CMAKE_CXX_FLAGS           "${CMAKE_CXX_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
      set(CMAKE_C_FLAGS             "${CMAKE_C_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
      if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
        set(CMAKE_CXX_FLAGS           "-mthumb ${CMAKE_CXX_FLAGS}")
        set(CMAKE_C_FLAGS             "-mthumb ${CMAKE_C_FLAGS}")
        set(CMAKE_EXE_LINKER_FLAGS    "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,nocopyreloc")
      endif()
      if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
        set(ARM_LINKER_FLAGS "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
      elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
        set(ARM_LINKER_FLAGS "-Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
      endif()
      set(CMAKE_SHARED_LINKER_FLAGS "${ARM_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
      set(CMAKE_MODULE_LINKER_FLAGS "${ARM_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
      set(CMAKE_EXE_LINKER_FLAGS    "${ARM_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
    else()
      #message(WARNING "CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}' is defined")
    endif()

    if(USE_NEON)
      message(WARNING "You use obsolete variable USE_NEON to enable NEON instruction set. Use -DENABLE_NEON=ON instead." )
      set(ENABLE_NEON TRUE)
    elseif(USE_VFPV3)
      message(WARNING "You use obsolete variable USE_VFPV3 to enable VFPV3 instruction set. Use -DENABLE_VFPV3=ON instead." )
      set(ENABLE_VFPV3 TRUE)
    endif()

    set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${ARM_LINUX_SYSROOT})

    if(EXISTS ${CUDA_TOOLKIT_ROOT_DIR})
      set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CUDA_TOOLKIT_ROOT_DIR})
    endif()

    set(TOOLCHAIN_CONFIG_VARS ${TOOLCHAIN_CONFIG_VARS}
        ARM_LINUX_SYSROOT
        ENABLE_NEON
        ENABLE_VFPV3
        CUDA_TOOLKIT_ROOT_DIR
    )
    toolchain_save_config()

,但是在运行cmake命令后仍然有以下输出:

命令:

khadas@Khadas:~/Downloads/opencv/platforms/linux/build_hardfp$ cmake -DBUILD_SHARED_LIBRARY=OFF -DLAPACK_LIBRARIES=/usr/lib/liblapack.a -DOPENCV_EXTRA_MODULES_PATH=/home/khadas/Downloads/opencv_contrib/modules -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..

输出:

-- General configuration for OpenCV 4.0.0-pre =====================================
--   Version control:               3.4.3-374-g475c775-dirty
-- 
--   Extra modules:
--     Location (extra):            /home/khadas/Downloads/opencv_contrib/modules
--     Version control (extra):     3.4.3-93-g3054618
-- 
--   Platform:
--     Timestamp:                   2018-09-24T09:23:39Z
--     Host:                        Linux 4.9.40 aarch64
--     Target:                      Linux 1 arm
--     CMake:                       3.5.1
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               Release
-- 
--   CPU/HW features:
--     Baseline:
--       requested:                 DETECT
--       disabled:                  VFPV3 NEON
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/arm-linux-gnueabi-g++  (ver 5.4.0)
--     C++ flags (Release):         -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/arm-linux-gnueabi-gcc
--     C flags (Release):           -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -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 -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -mfp16-format=ieee -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -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 -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -mfp16-format=ieee -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now    
--     Linker flags (Debug):        -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now    
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          dl m pthread rt
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann fuzzy hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    js world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java matlab ovis python2 python3 sfm viz
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   GUI: 
--     GTK+:                        NO
-- 
--   Media I/O: 
--     ZLib:                        build (ver 1.2.11)
--     JPEG:                        libjpeg-turbo (ver 1.5.3-62)
--     WEBP:                        build (ver encoder: 0x020e)
--     PNG:                         build (ver 1.6.34)
--     TIFF:                        build (ver 42 - 4.0.9)
--     JPEG 2000:                   build (ver 1.900.1)
--     OpenEXR:                     build (ver 1.7.1)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      NO
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   NO
--     libv4l/libv4l2:              NO
--     v4l/v4l2:                    linux/videodev2.h
-- 
--   Parallel framework:            pthreads
-- 
--   Trace:                         YES (built-in)
-- 
--   Other third-party libraries:
--     Lapack:                      NO
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.5.1)
-- 
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/khadas/Downloads/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   Python (for build):            /usr/bin/python2.7
-- 
--   Install to:                    /home/khadas/Downloads/opencv/platforms/linux/build_hardfp/install
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done

请在 Opencv模型下的输出中考虑以下行:

--     Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java matlab ovis python2 python3 sfm viz

谢谢!

2 个答案:

答案 0 :(得分:0)

我认为这不是解决此问题的最佳方法,但我是通过以下方式解决的:

  1. 安装cmake-guisudo apt-get install cmake-gui
  2. 删除构建文件夹的内容(以重新开始)
  3. 启动cmake-gui并配置内部版本
  4. 启用BUILD_JAVA参数
  5. 添加名为JAVA_HOME的新条目,该条目指向Java主目录
  6. 重新配置构建

然后cmake成功地识别了Java

答案 1 :(得分:0)

就其价值而言,在我的 Ubuntu 20.04.2 LTS、jdk-14 配置上,我需要将环境变量 ANT_HOME 设置为 /usr/share/ant。这消除了 /bin/ant 脚本中的错误消息,最终导致配置在 ant 上翻转为 Yes:

Java:                          
    ant:                         /bin/ant (ver 1.10.7)
    JNI:                         /usr/lib/jvm/jdk-14/include /usr/lib/jvm/jdk-14/include/linux /usr/lib/jvm/jdk-14/include
    Java wrappers:               YES
    Java tests:                  YES