1

I followed this tutorial, Cross compilation for ARM based Linux systems, in order to build Opencv version 3.3.1 using cmake for ARM based Linux system (Ubuntu Mate running on ODROID-XU4 Mini PC). For the build process i am running Ubuntu Mate v 16.04.1 x86.

Note that i already tried to build the same version of Opencv for my Intel x86 Ubuntu based running machine by following this tutorial, Opencv Installation in Linux, and i did it successfully. However when building it for ARM using the same machine, i got the following error.

-- The CXX compiler identification is unknown
-- The C compiler identification is unknown
CMake Error at CMakeLists.txt:114 (project):
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CXX" or the CMake cache entry CMAKE_CXX_COMPILER to the full path
  to the compiler, or to the compiler name if it is in the PATH.


CMake Error at CMakeLists.txt:114 (project):
  No CMAKE_C_COMPILER could be found.

  Tell CMake where to find the compiler by setting either the environment
  variable "CC" or the CMake cache entry CMAKE_C_COMPILER to the full path to
  the compiler, or to the compiler name if it is in the PATH.


-- Configuring incomplete, errors occurred!
See also "/home/jhon/Programs/opencv-3.3.1/arm/CMakeFiles/CMakeOutput.log".
See also "/home/jhon/Programs/opencv-3.3.1/arm/CMakeFiles/CMakeError.log".

Here is my command line that generates this error:

cmake -DCMAKE_TOOLCHAIN_FILE=../platforms/linux/arm-gnueabi.toolchain.cmake ..

Please note that the option -DCMAKE_TOOLCHAIN_FILE is what tells the cmake to build Opencv for the ARM based Linux systems and when i tried to remove it, i successfully ended up with building Opencv for my x86 machine without any errors.

Thanks in advance.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
HMaster
  • 49
  • 9
  • 1
    Aside from passing *CMAKE_TOOLCHAIN_FILE* option with appropriate toolchain, you need to **install compiler** for that toolchain: `sudo apt-get install gcc-arm-linux-gnueabi`. This is noted in the tutorial you refer to. – Tsyvarev Jan 31 '18 at 13:19
  • thanks @Tsyvarev but it is already installed, – HMaster Jan 31 '18 at 13:29
  • **gcc-arm-linux-gnueabi is already the newest version (4:5.3.1-1ubuntu1).** – HMaster Jan 31 '18 at 13:29
  • Hm, then the toolchain has been failed to find your compiler... Don't know why. Have you cleared build directory before switching to toolchain? (In other words, command `cmake -DCMAKE_TOOLCHAIN_FILE=...` should be executed in **empty** directory.) – Tsyvarev Jan 31 '18 at 13:46
  • Yes, i make sure that the build directory is empty before build but after trying to build and having the error some files are being generated by the cmake including the error log file that might help you, and here is a link for it: https://www.dropbox.com/s/ujjaap7u3hkl2hu/arm.zip?dl=0 – HMaster Jan 31 '18 at 13:57
  • Yes, this is actually helpful info. According to `CMakeFiles/toolchain.config.cmake`, toolchain has found C compiler (`/usr/bin/arm-linux-gnueabi-gcc`), but not the C++ one. And this is logic: the package `gcc-arm-linux-gnueabi` contains only C compiler, for C++ one need to install `g++-arm-linux-gnueabi`. Not sure why docs don't note that. – Tsyvarev Jan 31 '18 at 14:14
  • Thank you very much @Tsyvarev, it worked for me!!! please post it as an answer – HMaster Jan 31 '18 at 14:20

2 Answers2

1

OpenCV documentation tells to install only C cross-compiler (package gcc-arm-linux-gnueabi), but actually OpenCV requires C++ compiler too.

So one need to install g++-arm-linux-gnueabi package as well.

Tsyvarev
  • 60,011
  • 17
  • 110
  • 153
  • after passing the first issue i have a problem where cmake couldn't locate the Java although i export its path using export command, it says: **Java: -- ant: /usr/bin/ant (ver 1.9.6) -- JNI: NO -- Java wrappers: NO -- Java tests: NO** however when building for my local machine it finds it normally, any ideas please?!! thanks in advance – HMaster Jan 31 '18 at 16:54
  • What output is *without* cross-compiling? Note, that toolchain executes `set(CMAKE_FIND_ROOT_PATH /usr/arm-linux-gnueabi)`, and it expects everything (libraries, headers, programs) to be located under this directory, unless it is required only at the configure/build stages. I don't know, whether Java is required for build OpenCV or for run it. – Tsyvarev Jan 31 '18 at 17:08
  • without cross-compilation it outputs: `**-- Java: -- ant: /usr/bin/ant (ver 1.9.6) -- JNI: /usr/lib/jvm/default-java/include /usr/lib/jvm/default-java/include/linux /usr/lib/jvm/default-java/include -- Java wrappers: YES -- Java tests: YES**` , and Java is required for build OpenCV if you want to build the java .so files for java development. – HMaster Jan 31 '18 at 17:26
  • "Java is required for build OpenCV if you want to build the java .so files for java development." - So you need java libraries for target machine (ARM). Ones for host (x86) are not suitable for cross-compile. – Tsyvarev Jan 31 '18 at 19:24
  • Yes i figured this out and i tried to install the jdk for the target machine where in my case i had installed `jdk-8u162-linux-arm32-vfp-hflt` (that i am already running it on my target ARM machine - `ODROID XU4`) and before calling the cmake command i **exported** the path of the new jdk to the `JAVA_HOME` path variable but it is still not working. Could it be that the jdk i installed is not the suitable one for my target platform (knowing that it is already running successfully on my ODROID device)?! – HMaster Jan 31 '18 at 23:02
  • Assuming you have whole environment of your target machine mounted to some directory on the host, it is better to adjust toolchain for that directory by setting `ARM_LINUX_SYSROOT` variable: `cmake -DARM_LINUX_SYSROOT=<...> -DCMAKE_TOOLCHAIN_FILE=<...> `. Such a way CMake will search under this directory automatically. Note, that any hint about software location (like `JAVA_HOME` environment variable) should be **relative to the sysroot**. That is, if you have java at `/home/me/java`, you should set the variable to `/home/me/java`. – Tsyvarev Feb 01 '18 at 08:25
  • finally i had successfully built OpenCV for Java Linux for armv7hf by building it on the arm device itself not through cross compiling from Linux x64 or other – HMaster Feb 09 '18 at 10:27
0

I were always wondering why there is no pre-built binaries for Opencv-Linux (and i still don't know why) so here i put my work for public to benefit from it where it includes Opencv 3.3.1 pre-built versions for Linux x86, x64 and armv7hf (including corresponding java binaries).

OpenCV Linux x86, x62 & armv7hf binaries

HMaster
  • 49
  • 9