What I try to do is to cross compile OpenCV from a x86 host machine to an ARM target machine (Raspberry Pi 2) with Java bindings.
All I've achieved is to compile OpenCV with Java bindings for x86 platform, or even OpenCV with NO Java bindings for ARM platform. However I cannot compile OpenCV with Java bindings for ARM platform.
I've kind of followed thousands of guides to do this. This is from OpenCV's official site, and seems to be very simple: http://docs.opencv.org/2.4/doc/tutorials/introduction/crosscompilation/arm_crosscompile_with_cmake.html
My host machine is the following:
$ uname -a:
Linux ubuntu 4.2.0-16-generic #19-Ubuntu SMP Thu Oct 8 14:46:51 UTC 2015 i686 i686 i686 GNU/Linux
I've installed gcc and g++ cross compilation tools (gnueabi and gnueabihf):
$ sudo apt-get install gcc-arm-linux-gnueabi
$ sudo apt-get install g++-arm-linux-gnueabi
$ sudo apt-get install gcc-arm-linux-gnueabihf
$ sudo apt-get install g++-arm-linux-gnueabihf
$ which arm-linux-gnueabihf-gcc
/usr/bin/arm-linux-gnueabihf-gcc
$ which arm-linux-gnueabihf-g++
/usr/bin/arm-linux-gnueabihf-g++
Since I want to compile OpenCV with the Java bindings, I installed jdk and ant:
$ sudo apt-get install openjdk-7-jre
$ sudo apt-get install openjdk-7-jdk
$ sudo apt-get install ant
Then I add these lines to .bashrc file:
JAVA_HOME=/usr/lib/jvm/java-7-openjdk-i386
PATH=$JAVA_HOME/bin:$PATH
export PATH
Then I execute:
$ source $HOME/.bashrc
I've downloaded OpenCV's source code and moved to the platforms/linux folder as the official guide does:
$ cd ~/opencv/platforms/linux
$ mkdir -p build_hardfp
$ cd build_hardfp
Then in the "opencv/platforms/arm-gnueabi.toolchain.cmake" file, replaced these lines:
set(CMAKE_C_COMPILER arm-linux-gnueabi${FLOAT_ABI_SUFFIX}-gcc-${GCC_COMPILER_VERSION})
set(CMAKE_CXX_COMPILER arm-linux-gnueabi${FLOAT_ABI_SUFFIX}-g++-${GCC_COMPILER_VERSION})
by these:
set(CMAKE_C_COMPILER /usr/bin/arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER /usr/bin/arm-linux-gnueabihf-g++)
In order to use arm compiler instead of x86's.
Then I try to get cmake ready:
$ cmake -DBUILD_SHARED_LIBS=OFF -D BUILD_NEW_PYTHON_SUPPORT=NO -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..
Cmake's output tells it will use arm cross compiler for ARM platform target, but it will not use Java bindings:
...
-- Platform:
-- Host: Linux 4.2.0-16-generic i686
-- Target: Linux 1 arm
-- CMake: 3.2.2
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
-- Configuration: Release
...
C++ Compiler: /usr/bin/arm-linux-gnueabihf-g++ (ver 5.2.1)
...
-- OpenCV modules:
-- To be built: core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib stitching superres ts videostab
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: androidcamera dynamicuda java python viz
So, I try to set cmake compile variables by myself without using cmake's toolchain file:
$ export CMAKE_C_COMPILER=/usr/bin/arm-linux-gnueabihf-gcc
$ export CMAKE_CXX_COMPILER=/usr/bin/arm-linux-gnueabihf-g++
$ cmake -DBUILD_SHARED_LIBS=OFF -D BUILD_NEW_PYTHON_SUPPORT=NO ../../..
Now cmake's output tells it will include Java support, but it won't use arm cross compiler:
...
-- Platform:
-- Host: Linux 4.2.0-16-generic i686
-- CMake: 3.2.2
-- CMake generator: Unix Makefiles
-- CMake build tool: /usr/bin/make
-- Configuration: Release
...
C++ Compiler: /usr/bin/c++ (ver 5.2.1)
...
-- OpenCV modules:
-- To be built: core flann imgproc highgui features2d calib3d ml video legacy objdetect photo gpu ocl nonfree contrib java stitching superres ts videostab
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: androidcamera dynamicuda python viz
Of course, if I execute make command with this latest cmake configuration, this is the ".so" file I get:
$ readelf -h lib/libopencv_java249.so | grep Machine
Machine: Intel 80386
where it should tell:
Machine: ARM
So, once again: I can compile OpenCV with Java bindings for x86 platform, or either OpenCV with NO Java bindings for ARM platform, but not both.
How should I do this?
Thank you!
UPDATE 1:
#Notlikethat I forgot to tell I had already tried that (i.e. use ARM jdk instead of x86). I did not mention it because I though I should be using x86.
However, I have tried it again:
I've downloaded ARM's jdk, set JAVA_HOME and PATH variables properly to point this new jdk and tried cmake command.
The result is the same, it lets me compile for ARM without Java bingings, or for x86 with Java bindings.
UPDATE 2:
I've added the following variables to the "arm-gnueabi.toolchain.cmake" file:
set(JAVA_HOME /usr/lib/jvm/jdk1.7.0_60_ARM)
set(JAVA_AWT_LIBRARY $JAVA_HOME/include/jawt.h)
set(JAVA_JVM_LIBRARY $JAVA_HOME/jre/lib/arm/jvm.cfg)
set(JAVA_INCLUDE_PATH $JAVA_HOME/include/jni.h)
set(JAVA_INCLUDE_PATH2 $JAVA_HOME/include/linux/jni_md.h)
set(JAVA_AWT_INCLUDE_PATH $JAVA_HOME/include/jawt.h)
Now if I execute:
$ cmake -DBUILD_SHARED_LIBS=OFF -D BUILD_NEW_PYTHON_SUPPORT=NO -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..
the output shows that java module is still unavailable, but at least, one of its key dependencies is ok (JNI):
...
-- Java:
-- ant: NO
-- JNI: $JAVA_HOME/include/jni.h $JAVA_HOME/include/linux/jni_md.h $JAVA_HOME/include/jawt.h
-- Java tests: NO
...
I'm pretty sure the problem here is the fact that ant is not found, which I can't understand.
Ant is installed:
$ echo $PATH:/usr/lib/jvm/jdk1.7.0_60_ARM/bin:/opt/apache/ant/apache-ant-1.9.6/bin:...
I've retried by adding the following variables to the "arm-gnueabi.toolchain.cmake" file, without success:
set(ANT_HOME /opt/apache/ant/apache-ant-1.9.6)
set(JAVA_ANT $ANT_HOME/bin/ant)
Related
These are the step I follow to install doxygen 1.8.20:
apt-get install graphviz
apt-get install bison
apt-get install flex
wget http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.16.tar.gz
tar -xvzf libiconv-1.16.tar.gz
cd libiconv-1.16
./configure --prefix=/usr/local/libiconv
make
make install
wget http://doxygen.nl/files/doxygen-1.8.20.src.tar.gz
gunzip doxygen-1.8.20.src.tar.gz
tar -xf doxygen-1.8.20.src.tar
cd doxygen-1.8.20
mkdir build
cd build
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -Duse_libclang=ON ..
At this point I get the following output:
CMake Error at CMakeLists.txt:51 (find_package):
Could not find a package configuration file provided by "LLVM" with any of
the following names:
LLVMConfig.cmake
llvm-config.cmake
Add the installation prefix of "LLVM" to CMAKE_PREFIX_PATH or set
"LLVM_DIR" to a directory containing one of the above files. If "LLVM"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/home/doxygen-1.8.20/build/CMakeFiles/CMakeOutput.log".
Now I get LLVM package:
apt-get install llvm
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -Duse_libclang=ON ..
At this point I get the following output:
CMake Error at CMakeLists.txt:52 (find_package):
Could not find a package configuration file provided by "Clang" with any of
the following names:
ClangConfig.cmake
clang-config.cmake
Add the installation prefix of "Clang" to CMAKE_PREFIX_PATH or set
"Clang_DIR" to a directory containing one of the above files. If "Clang"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
Get clang package:
apt-get install clang
Get the same error:
CMake Error at CMakeLists.txt:52 (find_package):
Could not find a package configuration file provided by "Clang" with any of
the following names:
ClangConfig.cmake
clang-config.cmake
Add the installation prefix of "Clang" to CMAKE_PREFIX_PATH or set
"Clang_DIR" to a directory containing one of the above files. If "Clang"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/home/doxygen-1.8.20/build/CMakeFiles/CMakeOutput.log".
Now What?
This was found to be a problem with the llvm and clang that get installed with apt-get install llvm and apt-get install clang. This installs version 6 of both.
Instead of these commands, do the following:
apt install llvm-10 clang-10 libclang-10-dev
Then running
cmake -G "Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=/usr -Duse_libclang=ON ..
will produce successful output:
-- Found PythonInterp: /usr/bin/python (found version "2.7.17")
-- Found FLEX: /usr/bin/flex (found version "2.6.4")
-- Found BISON: /usr/bin/bison (found version "3.0.4")
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Failed
-- Looking for pthread_create in pthreads
-- Looking for pthread_create in pthreads - not found
-- Looking for pthread_create in pthread
-- Looking for pthread_create in pthread - found
-- Found Threads: TRUE
-- Looking for iconv_open
-- Looking for iconv_open - found
-- Performing Test ICONV_COMPILES
-- Performing Test ICONV_COMPILES - Success
-- Found Iconv: In glibc
-- One (and only one) of the ICONV_ACCEPTS_... tests must pass
-- Performing Test ICONV_ACCEPTS_NONCONST_INPUT
-- Performing Test ICONV_ACCEPTS_NONCONST_INPUT - Success
-- Performing Test ICONV_ACCEPTS_CONST_INPUT
-- Performing Test ICONV_ACCEPTS_CONST_INPUT - Failed
-- The javacc executable not found, using existing files
-- Configuring done
-- Generating done
-- Build files have been written to: /home/libiconv-1.16/doxygen-1.8.20/build
and proceed with make and make install
I am new to cmake though not to make. This question is different from Could not build OpenCV Android sample project since that other question is about a single project and this one is looking at the overall CMakeLists.txt.
Speaking of which: consider the CMakeLists.txt in ${OPENCVDIR}/samples :
I followed basic process for cmake:
cd "${OPENCVDIR}/samples"
mkdir build
cd build
cmake ..
But at the last step I have:
$ cmake ..
CMake Error at CMakeLists.txt:72 (find_package):
Could not find a package configuration file provided by "OpenCV" with any
of the following names:
OpenCVConfig.cmake
opencv-config.cmake
Add the installation prefix of "OpenCV" to CMAKE_PREFIX_PATH or set
"OpenCV_DIR" to a directory containing one of the above files. If "OpenCV"
provides a separate development package or SDK, be sure it has been
installed.
-- Configuring incomplete, errors occurred!
See also "/git/opencv/samples/CMakeFiles/CMakeOutput.log".
Line 72 has this: find_package(OpenCV REQUIRED PATHS "..")
I looked at the error log and it was not informative.
Compilation of the CXX compiler identification source "CMakeCXXCompilerId.cpp" produced "a.out"
The CXX compiler identification is GNU, found in "/git/opencv/samples/CMakeFiles/3.13.4/CompilerIdCXX/a.out"
Determining if the C compiler works passed with the following output:
Change Dir: /git/opencv/samples/CMakeFiles/CMakeTmp
Run Build Command:"/usr/bin/make" "cmTC_26f76/fast"
/usr/bin/make -f CMakeFiles/cmTC_26f76.dir/build.make CMakeFiles/cmTC_26f76.dir/build
make[1]: Entering directory '/git/opencv/samples/CMakeFiles/CMakeTmp'
Building C object CMakeFiles/cmTC_26f76.dir/testCCompiler.c.o
/usr/bin/cc -o CMakeFiles/cmTC_26f76.dir/testCCompiler.c.o -c /git/opencv/samples/CMakeFiles/CMakeTmp/testCCompiler.c
Linking C executable cmTC_26f76
/usr/bin/cmake -E cmake_link_script CMakeFiles/cmTC_26f76.dir/link.txt --verbose=1
/usr/bin/cc -rdynamic CMakeFiles/cmTC_26f76.dir/testCCompiler.c.o -o cmTC_26f76
make[1]: Leaving directory '/git/opencv/samples/CMakeFiles/CMakeTmp'
Detecting C compiler ABI info compiled with the following output:
"/git/opencv/samples/CMakeFiles/CMakeOutput.log" 706 lines, 48095 characters
Feature record: CXX_FEATURE:0cxx_defaulted_move_initializers
Feature record: CXX_FEATURE:0cxx_delegating_constructors
Feature record: CXX_FEATURE:0cxx_deleted_functions
Feature record: CXX_FEATURE:0cxx_digit_separators
Feature record: CXX_FEATURE:0cxx_enum_forward_declarations
Feature record: CXX_FEATURE:0cxx_explicit_conversions
Feature record: CXX_FEATURE:0cxx_extended_friend_declar
etc ..
What is the correct way to build these examples - hopefully using the CMakeLists.txt already provided?
It seems the installation directory of OpenCV couldn't be found by cmake. Try to provide the value through the argument:
cmake -DCMAKE_PREFIX_PATH=/home/someone/src/opencv/install ..
Ff it works, you could define this in the top-level CMakeLitst.txt:
list(APPEND CMAKE_PREFIX_PATH /home/someone/src/opencv/install)
This should provide CMake the place where it should look to.
$ opencv_version
3.4.16
$ cd OpenCV/samples/
$ cmake -B build
$ cmake --build build
JPEG display
$ build/cpp/example_cpp_image data/lena.jpg
USB camera capture
$ build/cpp/example_cpp_videocapture_basic
$ build/cpp/example_cpp_videocapture_camera
Recognition by AI
$ build/tapi/example_tapi_hog
I'm trying to install OpenCV with extra modules on a computer running Ubuntu 14.04.2 (I need this specific version of Ubuntu as I'm using some other hardware that requires it). I was able to do it on a Raspberry Pi 3 just last week (running Ubuntu Mate 16.04.3), but now I just can't seem to get it right.
I know that the opencv_contrib-version needs to be the same as the opencv-version, and I've tried building many different versions without luck (3.4.0, 3.3.0, 3.2.0, 3.1.0).
After downloading matching versions of opencv and opencv_contrib, I'm doing the following commands from the terminal:
$ cd opencv
$ mkdir build
$ cd build
$ cmake -D OPENCV_EXTRA_MODULES_PATH = ../../opencv_contrib/modules ..
where both opencv and opencv_contrib folders are located on the Desktop, so the "../../opencv_contrib/modules"-path should be correct.
But the extra modules aren't built. Here is parts of the cmake output:
-- OpenCV modules:
-- To be built: core flann imgproc ml objdetect photo video dnn imgcodecs shape videoio highgui superres ts features2d
calib3d stitching videostab
-- Disabled: world
-- Disabled by dependency: -
-- Unavailable: cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect
cudaoptflow cudastereo cudawarping cudev java python2 python3 viz
And as you can see, it's only the standard modules that are included. I've seen many people having the same issue, but the solution has always been about having the matching opencv/opencv_contrib versions. Now that I know that the versions are correct, I have no clue as to what I'm doing wrong.
You have extra spaces around the = in your cmake call, so the path does not get set correctly. Remove the two spaces and you should be fine:
cmake -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules ..
I tried this:
Alan#Alan ~/mercury
$ gfortran -o mercury6_2.for
gfortran.exe: fatal error: no input files; unwilling to write output files
compilation terminated
and:
Alan#Alan ~/mercury
$ gfortran -o mercury mercury6_2.for
gfortran.exe: error: CreateProcess: No such file or directory
My file exist:
Alan#Alan ~/mercury
$ ls
big.in element.in mercury.inc mercury6_2.for README.txt
close.in element6.for mercury6.man message.in small.in
close6.for files.in mercury6.tar param.in swift.incenter code here
gfortran seems to be running in Cygwin:
Alan#Alan ~/mercury
$ gfortran --version
GNU Fortran (GCC) 4.8.0 20130302 (experimental) [trunk revision 196403]
Copyright (C) 2013 Free Software Foundation, Inc.
GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING
So I don't know.
Is there away that I could do this differently?
I'm trying real hard to install vowpal wobbit and it fails when i run the make file, throwing:
cd library; make; cd ..
g++ -g -o ezexample temp2.cc -L ../vowpalwabbit -l vw -l allreduce -l boost_program_options -l z -l pthread
ld: library not found for -lboost_program_options collect2: ld returned 1 exit status make[1]: *** [ezexample] Error 1'
I then added the links to the boost library here by specifying -L/usr/local/lib
Now I get the following error:
g++ -g -o ezexample temp2.cc -L/usr/local/lib ../vowpalwabbit -l vw -l allreduce -l boost_program_options -l z -l pthread
ld: library not found for -lvw
collect2: ld returned 1 exit status
make: *** [ezexample] Error 1
I happened to get everything working on OS X 10.7 as follows:
Make sure you have a working Boost installation. As indicated on the Getting started page, usually we only need header files, but some Boost libraries must be built separately, including the program_options library which is used to process options from command line or config file. Go into your boost folder, and then at your shell prompt:
$ ./bootstrap.sh
$ ./bjam
This will compile and build everything. You should now have a bin.v2/ directory in your boost directory, with all built libraries for your system (static and threaded libs).
$ ls bin.v2/libs/
date_time iostreams python serialization test
filesystem math random signals thread
graph program_options regex system wave
More importantly, extra Boost libraries are made available in the stage/lib/ directory. For me, these are Mach-O 64-bit dynamically linked shared library x86_64.
The include path should be your_install_dir/boost_x_xx_x, where boost_x_xx_x is the basename of your working Boost. (I personally have boost_1_46_1 in /usr/local/share/ and I symlinked it to /usr/local/share/boost to avoid having to remember version number.) The library path (for linking) should read your_install_dir/boost_x_xx_x/stage/lib. However, it might be best to symlink or copy (which is what I did) everything in usual place, i.e. /usr/local/include/boost for header files, and /usr/local/lib for libraries.
Edit the Makefile from the vowpal_wabbit directory, and change the include/library paths to reflect your current installation. The Makefile should look like this (first 12 lines):
COMPILER = g++
UNAME := $(shell uname)
ifeq ($(UNAME), FreeBSD)
LIBS = -l boost_program_options -l pthread -l z -l compat
BOOST_INCLUDE = /usr/local/include
BOOST_LIBRARY = /usr/local/lib
else
LIBS = -l boost_program_options -l pthread -l z
BOOST_INCLUDE = /usr/local/share/boost # change path to reflect yours
BOOST_LIBRARY = /usr/local/share/boost/stage/lib # idem
endif
Then, you are ready to compile vowpal_wabbit (make clean in case you already compiled it):
$ make
$ ./vw --version
6.1
$ make test
You can also install vowpal wabbit on OS X using brew:
brew install vowpal-wabbit
Or you can just install boost, and then install vw from the github repo.
brew install boost
For installation on CentOS 7 (6.5 perl version is too old for latest vw source code), I've found the instructions at http://wkoplitz.blogspot.be/2012/12/vowpal-wabbit-on-centos.html to work fine:
yum install zlib-devel boost-devel
yum groupinstall "Development Tools"
git clone git://github.com/JohnLangford/vowpal_wabbit.git
cd vowpal_wabbit
./autogen.sh
make
make test
Good news:
As of the latest release VowpalWabbit version 9.1.0, vw no longer relies on Boost program_options
From the release highlights:
Removal of Boost Program Options dependency
For a long time we have depended on Boost Program Options
for command line options parsing. In this release, we have > replaced this dependency with our own implementation of
command line parsing. Apart from one place where we depend > on Boost Math in standalone mode, this means that VW core
and the command line tool are free of Boost dependencies
hopefully making the code a bit easier to build and package.
Vowpal Wabbit 9.1.0 release notes