@kazu_son

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

Opencv v2.4のarm8ビルドの方法

概要

Opencvを利用したC++のコードをAndroidのarm8ライブラリとしてビルドを行いたいです。
依存関係にあるため、ビルド時にOpencvのAndroidライブラリ(.soや.a)が必要になります。
しかし、Opencvのv2.4.13.5ではAndroidのarm64-v8aビルドをサポートしていませんでした。
arm64-v8aをビルドする方法を教えてほしいです。

環境

Opencv v2.4.15.5
Windows
Android NDK r25c
VSCode v1.81.1

試したこと

ChatGPTに聞いて以下のような手順を行いました。
(以下はChatGPTより抜粋)

1. Android NDKのインストール:
Android用のNDKをインストールします。OpenCV 2.4.15.5は比較的古いバージョンのため、適切なNDKバージョンを使用する必要があります。適切なNDKバージョンはOpenCVの公式ドキュメントを確認してください。

2. OpenCVのソースコードの取得:
OpenCV 2.4.15.5のソースコードを入手します。公式のGitHubリポジトリからソースコードをクローンするか、ダウンロードしてください。

3. ビルド設定の構築:
ターミナルを開き、OpenCVのソースコードディレクトリに移動します。次に、Android用のビルド設定を行います。android-opencvという名前のディレクトリを作成し、その中に移動します。

android-opencvフォルダ内でバッチファイルを用意し実行しました。

build.bat
set ANDROID_NDK=C:\work\android-ndk-r25c

cmake -G "MSYS Makefiles" ^
-DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK%\build\cmake\android.toolchain.cmake ^
-DANDROID_ABI=arm64-v8a ^
-DANDROID_NATIVE_API_LEVEL=21 ^
-DCMAKE_SYSROOT=%ANDROID_NDK%\toolchains\llvm\prebuilt\windows-x86_64\sysroot ^
C:\work\opencv-2.4.13.5
PS C:\work\opencv-2.4.13.5\android-opencv> .\build.bat

以下のようなエラーが出ております。

C:\work\opencv-2.4.13.5\android-opencv>set ANDROID_NDK=C:\work\android-ndk-r25c

C:\work\opencv-2.4.13.5\android-opencv>cmake -G "MSYS Makefiles" -DCMAKE_TOOLCHAIN_FILE=C:\work\android-ndk-r25c\build\cmake\android.toolchain.cmake -DANDROID_ABI=arm64-v8a -DANDROID_NATIVE_API_LEVEL=21 -DCMAKE_SYSROOT=C:\work\android-ndk-r25c\toolchains\llvm\prebuilt\windows-x86_64\sysroot C:\work\opencv-2.4.13.5
CMake Deprecation Warning at CMakeLists.txt:53 (cmake_policy):
  The OLD behavior for policy CMP0042 will be removed from a future version
  of CMake.

  The cmake-policies(7) manual explains that the OLD behaviors of all
  policies are deprecated and that a policy should be set to OLD only under
  specific short-term circumstances.  Projects should be ported to the NEW
  behavior and not rely on setting a policy to OLD.


-- The CXX compiler identification is Clang 14.0.7
-- The C compiler identification is Clang 14.0.7
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/work/android-ndk-r25c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe
-- Check for working CXX compiler: C:/work/android-ndk-r25c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe - broken
CMake Error at D:/Program Files/CMake/share/cmake-3.26/Modules/CMakeTestCXXCompiler.cmake:60 (message):
  The C++ compiler

    "C:/work/android-ndk-r25c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: C:/work/opencv-2.4.13.5/android-opencv/CMakeFiles/CMakeScratch/TryCompile-pdr2k0

    Run Build Command(s):D:/Program Files/CMake/bin/cmake.exe -E env VERBOSE=1 D:/Tools/GnuWin32/bin/make.exe -f Makefile cmTC_0d92b/fast && D:/Tools/GnuWin32/bin/make.exe  -f CMakeFiles/cmTC_0d92b.dir/build.make CMakeFiles/cmTC_0d92b.dir/build
    make.exe[1]: ディレクトリ `C:/work/opencv-2.4.13.5/android-opencv/CMakeFiles/CMakeScratch/TryCompile-pdr2k0' に入ります
    指定されたパスが見つかりません。
    make.exe[1]: *** [CMakeFiles/cmTC_0d92b.dir/testCXXCompiler.cxx.o] エラー 1
    make.exe[1]: ディレクトリ `C:/work/opencv-2.4.13.5/android-opencv/CMakeFiles/CMakeScratch/TryCompile-pdr2k0' から出ます
    make.exe: *** [cmTC_0d92b/fast] エラー 2





  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:64 (project)


-- Configuring incomplete, errors occurred!
0 likes

No Answers yet.

Your answer might help someone💌