Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CMake error with OpenCV #1315

Closed
prerna-khanna opened this issue Jul 23, 2018 · 19 comments
Closed

CMake error with OpenCV #1315

prerna-khanna opened this issue Jul 23, 2018 · 19 comments

Comments

@prerna-khanna
Copy link

This is the log file

[INFO]:    Building opencv for armeabi-v7a
[INFO]:    -> directory context /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv
[INFO]:    -> running cmake -DP4A=ON -DANDROID_ABI=armeabi-v7a -DCMAKE_TOOLCHAIN_FILE=/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/o...(and 890 more)
           working: ThisException in thread background thread for pid 23973:                                                                                                                   
Traceback (most recent call last):
  File "/usr/lib/python2.7/threading.py", line 801, in __bootstrap_inner
    self.run()
  File "/usr/lib/python2.7/threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 2170, in background_thread
    handle_exit_code(exit_code)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 1929, in fn
    return self.command.handle_command_exit_code(exit_code)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 672, in handle_command_exit_code
    raise exc
ErrorReturnCode_1: 

  RAN: /usr/local/bin/cmake -DP4A=ON -DANDROID_ABI=armeabi-v7a -DCMAKE_TOOLCHAIN_FILE=/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv/platforms/android/android.toolchain.cmake -DPYTHON_INCLUDE_PATH=/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/include/python2.7 -DPYTHON_LIBRARY=/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/libpython2.7.so -DPYTHON_NUMPY_INCLUDE_DIR=/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/site-packages/numpy/core/include -DANDROID_EXECUTABLE=/home/kivy/.buildozer/android/platform/android-sdk-20/tools/android -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_ANDROID_EXAMPLES=OFF -DPYTHON_PACKAGES_PATH=/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/site-packages /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv

  STDOUT:
CMake Deprecation Warning at CMakeLists.txt:47 (cmake_policy):
  The OLD behavior for policy CMP0022 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.


CMake Deprecation Warning at /usr/local/lib/python2.7/dist-packages/cmake/data/share/cmake-3.12/Modules/CMakeForceCompiler.cmake:69 (message):
  The CMAKE_FORCE_C_COMPILER macro is deprecated.  Instead just set
  CMAKE_C_COMPILER and allow CMake to identify the compiler.
Call Stack (most recent call first):
  platforms/android/android.toolchain.cmake:1204 (CMAKE_FORCE_C_COMPILER)
  CMakeFiles/3.12.0/CMakeSystem.cmake:6 (include)
  CMakeLists.txt:56 (project)


CMake Deprecation Warning at /usr/local/lib/python2.7/dist-packages/cmake/data/share/cmake-3.12/Modules/CMakeForceCompiler.cmake:83 (message):
  The CMAKE_FORCE_CXX_COMPILER macro is deprecated.  Instead just set
  CMAKE_CXX_COMPILER and allow CMake to identify the compiler.
Call Stack (most recent call first):
  platforms/android/android.toolchain.cmake:1212 (CMAKE_FORCE_CXX_COMPILER)
  CMakeFiles/3.12.0/CMakeSystem.cmake:6 (include)
  CMakeLists.txt:56 (project)


CMake Warning (dev) at platforms/android/android.toolchain.cmake:1668 (if):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "LIBRARY_OUTPUT_PATH_ROOT" will no longer be
  dereferenced when the policy is set to NEW.  Since the policy is not set
  the OLD behavior will be used.
Call Stack (most recent call first):
  CMakeFiles/3.12.0/CMakeSystem.cmake:6 (include)
  CMakeLists.txt:56 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
-- Configuring incomplete, errors occurred!
See also "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv/CMakeFiles/CMakeOutput.log".


  STDERR:


Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/kivy/Desktop/Manual /new/python-for-android/pythonforandroid/toolchain.py", line 977, in <module>
    main()
  File "/home/kivy/Desktop/Manual /new/python-for-android/pythonforandroid/toolchain.py", line 973, in main
    ToolchainCL()
  File "/home/kivy/Desktop/Manual /new/python-for-android/pythonforandroid/toolchain.py", line 512, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/kivy/Desktop/Manual /new/python-for-android/pythonforandroid/toolchain.py", line 147, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/kivy/Desktop/Manual /new/python-for-android/pythonforandroid/toolchain.py", line 191, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx)
  File "pythonforandroid/build.py", line 573, in build_recipes
  File "/home/kivy/Desktop/Manual /new/python-for-android/pythonforandroid/recipes/opencv/__init__.py", line 46, in build_arch
    _env=env)
  File "pythonforandroid/logger.py", line 176, in shprint
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 720, in next
    self.wait()
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 651, in wait
    self.handle_command_exit_code(exit_code)
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 672, in handle_command_exit_code
    raise exc
sh.ErrorReturnCode_1: 

  RAN: /usr/local/bin/cmake -DP4A=ON -DANDROID_ABI=armeabi-v7a -DCMAKE_TOOLCHAIN_FILE=/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv/platforms/android/android.toolchain.cmake -DPYTHON_INCLUDE_PATH=/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/include/python2.7 -DPYTHON_LIBRARY=/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/libpython2.7.so -DPYTHON_NUMPY_INCLUDE_DIR=/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/site-packages/numpy/core/include -DANDROID_EXECUTABLE=/home/kivy/.buildozer/android/platform/android-sdk-20/tools/android -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_ANDROID_EXAMPLES=OFF -DPYTHON_PACKAGES_PATH=/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/python-installs/myapp/lib/python2.7/site-packages /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv

  STDOUT:
CMake Deprecation Warning at CMakeLists.txt:47 (cmake_policy):
  The OLD behavior for policy CMP0022 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.


CMake Deprecation Warning at /usr/local/lib/python2.7/dist-packages/cmake/data/share/cmake-3.12/Modules/CMakeForceCompiler.cmake:69 (message):
  The CMAKE_FORCE_C_COMPILER macro is deprecated.  Instead just set
  CMAKE_C_COMPILER and allow CMake to identify the compiler.
Call Stack (most recent call first):
  platforms/android/android.toolchain.cmake:1204 (CMAKE_FORCE_C_COMPILER)
  CMakeFiles/3.12.0/CMakeSystem.cmake:6 (include)
  CMakeLists.txt:56 (project)


CMake Deprecation Warning at /usr/local/lib/python2.7/dist-packages/cmake/data/share/cmake-3.12/Modules/CMakeForceCompiler.cmake:83 (message):
  The CMAKE_FORCE_CXX_COMPILER macro is deprecated.  Instead just set
  CMAKE_CXX_COMPILER and allow CMake to identify the compiler.
Call Stack (most recent call first):
  platforms/android/android.toolchain.cmake:1212 (CMAKE_FORCE_CXX_COMPILER)
  CMakeFiles/3.12.0/CMakeSystem.cmake:6 (include)
  CMakeLists.txt:56 (project)


CMake Warning (dev) at platforms/android/android.toolchain.cmake:1668 (if):
  Policy CMP0054 is not set: Only interpret if() arguments as variables or
  keywords when unquoted.  Run "cmake --help-policy CMP0054" for policy
  details.  Use the cmake_policy command to set the policy and suppress this
  warning.

  Quoted variables like "LIBRARY_OUTPUT_PATH_ROOT" will no longer be
  dereferenced when the policy is set to NEW.  Since the policy is not set
  the OLD behavior will be used.
Call Stack (most recent call first):
  CMakeFiles/3.12.0/CMakeSystem.cmake:6 (include)
  CMakeLists.txt:56 (project)
This warning is for project developers.  Use -Wno-dev to suppress it.

CMake Error: CMake was unable to find a build program corresponding to "Unix Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
-- Configuring incomplete, errors occurred!
See also "/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv/CMakeFiles/CMakeOutput.log".


  STDERR:

# Command failed: /usr/bin/python -m pythonforandroid.toolchain create --dist_name=myapp --bootstrap=sdl2 --requirements=kivy,opencv --arch armeabi-v7a --copy-libs --color=always --storage-dir=/home/kivy/Desktop/Cam/.buildozer/android/platform/build

CMake file log shows:

The target system is: Linux - 1 - armv7-a
The host system is: Linux - 4.10.0-20-generic - x86_64
@tanmay-1srivastava
Copy link

tanmay-1srivastava commented Jul 24, 2018

I am facing the same issue. can anyone here help me out
@AndreMiras

@AndreMiras
Copy link
Member

@prerna-khanna could you share that log file /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv/CMakeFiles/CMakeOutput.log?

@prerna-khanna
Copy link
Author

The target system is: Linux - 1 - armv7-a
The host system is: Linux - 4.10.0-20-generic - x86_64

This is the log file

@AndreMiras
Copy link
Member

I don't see you mean that's the only content of the CMakeOutput.log file? OK that's super unhelpful 😕
Do you have cmake installed? Also make sure you have all the deps as described in https://buildozer.readthedocs.io/en/latest/installation.html#android-on-ubuntu-16-04-64bit
Without log file, it's hard to guess to be honest 😞

@prerna-khanna
Copy link
Author

prerna-khanna commented Jul 25, 2018

@AndreMiras yes that's the only thing mentioned in the log file and I am using VM.
To elaborate more on the problem, initially the error was:

[INFO]:    Building opencv for armeabi-v7a
[INFO]:    -> directory context /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv
Traceback (most recent call last):
  File "/usr/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/home/kivy/Desktop/Manual /new/python-for-android/pythonforandroid/toolchain.py", line 977, in <module>
    main()
  File "/home/kivy/Desktop/Manual /new/python-for-android/pythonforandroid/toolchain.py", line 973, in main
    ToolchainCL()
  File "/home/kivy/Desktop/Manual /new/python-for-android/pythonforandroid/toolchain.py", line 512, in __init__
    getattr(self, args.subparser_name.replace('-', '_'))(args)
  File "/home/kivy/Desktop/Manual /new/python-for-android/pythonforandroid/toolchain.py", line 147, in wrapper_func
    build_dist_from_args(ctx, dist, args)
  File "/home/kivy/Desktop/Manual /new/python-for-android/pythonforandroid/toolchain.py", line 191, in build_dist_from_args
    build_recipes(build_order, python_modules, ctx)
  File "pythonforandroid/build.py", line 573, in build_recipes
  File "/home/kivy/Desktop/Manual /new/python-for-android/pythonforandroid/recipes/opencv/__init__.py", line 36, in build_arch
    shprint(sh.cmake,
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 3054, in __getattr__
    return self.__env[name]
  File "/usr/local/lib/python2.7/dist-packages/sh.py", line 2931, in __getitem__
    raise CommandNotFound(k)
sh.CommandNotFound: cmake

Then I installed make and CMake by sudo apt-get install make and sudo pip install cmake.
After installing these I landed to this error.

After reading the buildozer log, I figured that /home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv/CMakeFiles/3.12.0/CMakeSystem.cmake
contains this version:

set(CMAKE_HOST_SYSTEM "Linux-4.10.0-20-generic")
set(CMAKE_HOST_SYSTEM_NAME "Linux")
set(CMAKE_HOST_SYSTEM_VERSION "4.10.0-20-generic")
set(CMAKE_HOST_SYSTEM_PROCESSOR "x86_64")

include("/home/kivy/Desktop/Cam/.buildozer/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv/platforms/android/android.toolchain.cmake")


set(CMAKE_SYSTEM "Linux-1")
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_VERSION "1")
set(CMAKE_SYSTEM_PROCESSOR "armv7-a")

set(CMAKE_CROSSCOMPILING "TRUE")

set(CMAKE_SYSTEM_LOADED 1)

I tried changing the version here, but it didn't help.

@jatupolseeti
Copy link

I have same issue.
Please help.

These are my log files.
my_log.txt
CMakeOutput.log

@jatupolseeti
Copy link

Help me please.

This is my buildozer.spec.
buildozer_spec.txt

@AndreMiras

@AndreMiras
Copy link
Member

Your CMakeOutput.log is surprising empty.
Also make sure you compile on p4a master branch.
p4a.branch = master
This bug tracker is not for support request 😕

@jatupolseeti
Copy link

Your CMakeOutput.log is surprising empty.
Also make sure you compile on p4a master branch.
p4a.branch = master
This bug tracker is not for support request confused

@AndreMiras
I got same errors.
my_log.txt
buildozer_spec.txt
CMakeOutput.log

@tito
Copy link
Member

tito commented Oct 6, 2018

The error about OLD maybe indicate that the CMakefile is using old stuff not supported by recent CMake, so maybe the OpenCV version in the recipes is just too old for the current tooling?
So someone should try to fix the recipe by updating the version number and fixes the patches if they are?

@jatupolseeti
Copy link

The error about OLD maybe indicate that the CMakefile is using old stuff not supported by recent CMake, so maybe the OpenCV version in the recipes is just too old for the current tooling?
So someone should try to fix the recipe by updating the version number and fixes the patches if they are?

Thank you @tito .

Could you please help update recipe?

@tito
Copy link
Member

tito commented Oct 6, 2018

No, but you could try it yourself! Clone Python-for-android, edit the recipe, try to update to latest opencv, compile, and go error by error until it compiles :)
Use Google, Stackoverflow and others recipes to get it working!

@jatupolseeti
Copy link

I modified the opencv recipe as as following.


import os
import sh
from pythonforandroid.recipe import NDKRecipe
from pythonforandroid.toolchain import (
current_directory,
shprint,
)
from multiprocessing import cpu_count

class OpenCVRecipe(NDKRecipe):
version = '3.4.1'
url = 'https://github.com/Itseez/opencv/archive/{version}.zip'
#md5sum = '2ddfa98e867e6611254040df841186dc'
depends = ['numpy']
#patches = ['patches/p4a_build-2.4.10.1.patch']
generated_libraries = ['cv2.so']

def prebuild_arch(self, arch):
    self.apply_patches(arch)

def get_recipe_env(self, arch):
    env = super(OpenCVRecipe, self).get_recipe_env(arch)
    env['PYTHON_ROOT'] = self.ctx.get_python_install_dir()
    env['ANDROID_NDK'] = self.ctx.ndk_dir
    env['ANDROID_SDK'] = self.ctx.sdk_dir
    env['SITEPACKAGES_PATH'] = self.ctx.get_site_packages_dir()
    return env

def build_arch(self, arch):
    with current_directory(self.get_build_dir(arch.arch)):
        env = self.get_recipe_env(arch)
        cvsrc = self.get_build_dir(arch.arch)
        lib_dir = os.path.join(self.ctx.get_python_install_dir(), "lib")

        shprint(sh.cmake,
                '-DP4A=ON', '-DANDROID_ABI={}'.format(arch.arch),
                '-DCMAKE_TOOLCHAIN_FILE={}/platforms/android/android.toolchain.cmake'.format(cvsrc),
                '-DPYTHON_INCLUDE_PATH={}/include/python3.6'.format(env['PYTHON_ROOT']),
                '-DPYTHON_LIBRARY={}/lib/libpython3.6.so'.format(env['PYTHON_ROOT']),
                '-DPYTHON_NUMPY_INCLUDE_DIR={}/numpy/core/include'.format(env['SITEPACKAGES_PATH']),
                '-DANDROID_EXECUTABLE={}/tools/android'.format(env['ANDROID_SDK']),
                '-DBUILD_TESTS=OFF', '-DBUILD_PERF_TESTS=OFF',
                '-DBUILD_EXAMPLES=OFF', '-DBUILD_ANDROID_EXAMPLES=OFF',
                '-DPYTHON_PACKAGES_PATH={}'.format(env['SITEPACKAGES_PATH']),
                cvsrc,
                _env=env)
        shprint(sh.make, '-j', str(cpu_count()), 'opencv_python')
        shprint(sh.cmake, '-DCOMPONENT=python', '-P', './cmake_install.cmake')
        sh.cp('-a', sh.glob('./lib/{}/lib*.so'.format(arch.arch)), lib_dir)

recipe = OpenCVRecipe()


I got error:

sh.ErrorReturnCode_1:

RAN: /usr/local/bin/cmake -DP4A=ON -DANDROID_ABI=armeabi-v7a -DCMAKE_TOOLCHAIN_FILE=/home/ubuntu/build/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv/platforms/android/android.toolchain.cmake -DPYTHON_INCLUDE_PATH=/home/ubuntu/build/android/platform/build/build/python-installs/simpleapp/include/python3.6 -DPYTHON_LIBRARY=/home/ubuntu/build/android/platform/build/build/python-installs/simpleapp/lib/libpython3.6.so -DPYTHON_NUMPY_INCLUDE_DIR=/home/ubuntu/build/android/platform/build/build/python-installs/simpleapp/numpy/core/include -DANDROID_EXECUTABLE=/home/ubuntu/.buildozer/android/platform/android-sdk-20/tools/android -DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_ANDROID_EXAMPLES=OFF -DPYTHON_PACKAGES_PATH=/home/ubuntu/build/android/platform/build/build/python-installs/simpleapp /home/ubuntu/build/android/platform/build/build/other_builds/opencv/armeabi-v7a/opencv

STDOUT:
CMake Error at CMakeLists.txt:11 (message):

FATAL: In-source builds are not allowed.

     You should create a separate directory for build files.

-- Configuring incomplete, errors occurred!

How to fix it?

@inclement
Copy link
Member

Closing as stale, not sure if opencv still has issues but it should have at least improved since then.

@RobertFlatt
Copy link
Contributor

I don't think it is stale. I'm still trying to figure out how to get OpenCV to build.
And today somebody in the user group has the same problem:
https://groups.google.com/forum/#!topic/kivy-users/ynE7Av0z1ec

@AndreMiras
Copy link
Member

Thanks @Ham-Merhead for the head-up. I hope someone find time/energy to look into it

@AndreMiras AndreMiras reopened this Jan 31, 2019
@RobertFlatt
Copy link
Contributor

The user group member found a solution in a p4a fork created 2 months ago.

I found a solution by myself, so posting it here for future reference of others.

This solution worked (sdk=24,ndk=15b,api=27) - with a fork of p4a branch (https://github.com/zworkb/python-for-android):

The repo has changed opencv patch file and so has the cmake error solved.

@AndreMiras
Copy link
Member

AndreMiras commented Feb 1, 2019

There's now a WIP PR #1650 🎉
It's a pretty early draft, but it compiles in my Docker environment and produces two static libraries. Let's see what Travis says. If it goes green I think we could merge and work from there 😄

Edit:
Travis also happy, see conditional build log: https://travis-ci.org/kivy/python-for-android/jobs/487232388
And relevant part of the logs:

working: [ 97%] Linking CXX static library ../../lib/armeabi-v7a/libopencv_core.a   �[0m
working: [ 97%] Built target opencv_core                                            �[0m
working: Scanning dependencies of target opencv_ml                                  �[0m
...
working: [100%] Linking CXX static library ../../lib/armeabi-v7a/libopencv_ml.a     �[0m
working: [100%] Built target opencv_ml                                              �[0m

@inclement
Copy link
Member

Fixed by #1650, other fixes can follow from that if necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants