簡體   English   中英

Cmake無法在構建OpenCv時識別Java

[英]Cmake cannot recognize java while building OpenCv

我正在嘗試在Khadas Vim2構建OpenCv ,該產品使用CMake預先安裝了具有基於64位ARM的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 Models下的輸出中考慮以下行:

--     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

提前致謝!!

我認為這不是解決此問題的最佳方法,但我可以通過以下方式解決:

  1. 安裝cmake-guisudo apt-get install cmake-gui
  2. 刪除構建文件夾的內容(重新開始)
  3. 啟動cmake-gui並配置構建
  4. 啟用BUILD_JAVA參數
  5. 添加名為JAVA_HOME新條目,該條目指向Java主目錄
  6. 再次配置構建

然后cmake成功識別java

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM