Ask Your Question
0

Help compiling to Linux arm64

asked 2018-03-28 10:08:49 -0600

NadavR gravatar image

updated 2018-05-07 14:16:29 -0600

Hello,

@tomoaki0705 said this is a good place to ask for help on opencv on this topic.

As you can see in the link, I'm having trouble compiling OpenCV to Linux (Debian) arm64. This is what I'm using right now, copied from the github issue, slightly edited to not disable neon:

Cross compile using an extended dockcross script. Let's call it linux-arm64 and save it in a folder called dockerfiles

FROM dockcross/linux-arm64

ENV DEFAULT_DOCKCROSS_IMAGE linux-arm64

# Set up CCache
RUN apt-get -y install ccache
ENV CCACHE_DIR=/.ccache
RUN mkdir /.ccache
RUN chmod 777 /.ccache

# Install required libraries
RUN apt-get -y install libavcodec-dev:arm64 libavformat-dev:arm64 libswscale-dev:arm64 libjpeg-dev:arm64 libpng-dev:arm64 libtiff-dev:arm64 libdc1394-22:arm64 libdc1394-22-dev:arm64
RUN apt-get -y install --no-install-recommends libgtk2.0-dev:arm64


# cd to /opencv and download OpenCV source
WORKDIR /opencv
RUN wget https://github.com/opencv/opencv/archive/3.4.0.zip
RUN apt-get install unzip
RUN unzip 3.4.0.zip
RUN ln -s /opencv/opencv-3.4.0 /opencv/opencv

# Create build folder
WORKDIR /opencv/opencv
RUN mkdir /opencv/opencv/build
WORKDIR /opencv/opencv/build

ENV PKG_CONFIG_PATH /usr/lib/aarch64-linux-gnu/pkgconfig/

# Build OpenCV
# ##### The command I really want to use, commented out in favor of a simplified example. RUN cmake -DBUILD_SHARED_LIBS=OFF -DCMAKE_MAKE_PROGRAM=make -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_QT=OFF -DBUILD_EXAMPLES=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF -DBUILD_opencv_cudabgsegm=OFF -DBUILD_opencv_superres=OFF -DBUILD_opencv_cudalegacy=OFF -DBUILD_opencv_cudafilters=OFF -DBUILD_opencv_cudastereo=OFF -DBUILD_opencv_cudafeatures2d=OFF -DBUILD_opencv_shape=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_stitching=OFF -DBUILD_opencv_python_bindings_generator=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_cudaoptflow=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_calib3d=OFF -DBUILD_opencv_videostab=OFF -DBUILD_opencv_cudacodec=OFF -DBUILD_opencv_core=ON -DBUILD_opencv_cudaimgproc=OFF -DBUILD_opencv_dnn=OFF -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_cudev=OFF -DBUILD_opencv_video=OFF -DBUILD_opencv_cudawarping=OFF -DBUILD_opencv_cudaarithm=OFF -DBUILD_opencv_features2d=OFF -DBUILD_opencv_cudaobjdetect=OFF -DBUILD_opencv_flann=OFF -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE .. 
RUN cmake -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE  ..
RUN make -j7
RUN make install

WORKDIR /work

Run the following in terminal: docker build -f dockerfiles/linux-arm64 -t linux-arm64 .

I'm also trying to use clang as an alternative, to no avail yet. Constructing a CMake toolchain for clang is proving very difficult.

edit retag flag offensive close merge delete

Comments

Additional question,

Is really "/usr/bin/aarch64-linux-gnu-c++" linked to "/usr/bin/aarch64-linux-gnu-g++" ?

What happens if you do "ls -l /usr/bin/aarch64-linux-gnu-c++" ?

-- Check for working CXX compiler: /usr/bin/aarch64-linux-gnu-c++
-- Check for working CXX compiler: /usr/bin/aarch64-linux-gnu-c++ -- works

--     C++ Compiler:                /usr/bin/aarch64-linux-gnu-c++  (ver 4.9.2)

These line really looks like your cmake didn't find g++ correctly. Are you really sure that you're using the correct compiler for cross compilation ?

tomoaki0705 gravatar imagetomoaki0705 ( 2018-03-28 20:00:15 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2018-05-06 07:21:49 -0600

NadavR gravatar image

updated 2018-05-13 02:59:33 -0600

It wasn't easy, but I solved it. Dockcross was using a deprecated tool named embedian. I have since made a pull request to Dockcross that uses a tool named crosstool-ng. However, there seems to be a bug either in OpenCV or Debian's pkg-config, and I had to use soft links to make the compilation possible. Here is how my dockerfile looks, feel free to use it:

EDIT: Change dockerfile to reflect changed made in the Dockcross image:

FROM dockcross/linux-arm64
ENV DEFAULT_DOCKCROSS_IMAGE linux-arm64
# Set up CCache
RUN apt-get -y install ccache
ENV CCACHE_DIR=/.ccache
RUN mkdir /.ccache
RUN chmod 777 /.ccache

# Install required libraries
RUN apt-get -y install wget gawk gperf help2man texinfo gcc gperf bison flex texinfo make libncurses5-dev python-dev unzip
RUN apt-get -y install libavcodec-dev:arm64 libavformat-dev:arm64 libswscale-dev:arm64 libjpeg-dev:arm64 libpng-dev:arm64 libtiff-dev:arm64 libdc1394-22:arm64 libdc1394-22-dev:arm64 libv4l-dev:arm64 ffmpeg:arm64
RUN apt-get -y install --no-install-recommends libgtk2.0-dev:arm64
RUN apt-get clean --yes

# cd to /opencv and download OpenCV source
WORKDIR /opencv
RUN wget https://github.com/opencv/opencv/archive/3.4.0.tar.gz
RUN tar xvf 3.4.0.tar.gz

# necessary hacks
RUN ln -s /usr/include/dc1394/ /usr/bin/aarch64-unknown-linux-gnueabi/include/dc1394 &&  \ 
ln -s /usr/include/libavformat/ /usr/bin/aarch64-unknown-linux-gnueabi/include/libavformat &&  \ 
ln -s /usr/include/libavcodec/ /usr/bin/aarch64-unknown-linux-gnueabi/include/libavcodec &&  \ 
ln -s /usr/include/libavutil/ /usr/bin/aarch64-unknown-linux-gnueabi/include/libavutil &&  \ 
ln -s /usr/include/libswscale/ /usr/bin/aarch64-unknown-linux-gnueabi/include/libswscale &&  \ 
ln -s /usr/include/libv4l1.h /usr/bin/aarch64-unknown-linux-gnueabi/include/libv4l1.h &&  \ 
ln -s /usr/include/libv4l1-videodev.h /usr/bin/aarch64-unknown-linux-gnueabi/include/libv4l1-videodev.h &&  \ 
ln -s /usr/include/libv4l2.h /usr/bin/aarch64-unknown-linux-gnueabi/include/libv4l2.h
ENV CXXFLAGS "-D__STDC_CONSTANT_MACROS"

# Build OpenCV
WORKDIR /opencv/opencv-3.4.0/build
RUN cmake -DWITH_V4L=ON -DWITH_1394=ON -DWITH_LIBV4L=ON -DINSTALL_C_EXAMPLES=OFF -DWITH_GTK=ON -DBUILD_SHARED_LIBS=OFF -DCMAKE_MAKE_PROGRAM=make -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=/usr/local -DWITH_OPENGL=ON -DWITH_GDAL=ON -DWITH_XINE=ON -DBUILD_EXAMPLES=OFF -DBUILD_PERF_TESTS=OFF -DBUILD_TESTS=OFF -DBUILD_DOCS=OFF  -DWITH_FFMPEG=ON -DENABLE_NEON=ON -DBUILD_opencv_cudabgsegm=OFF -DBUILD_opencv_superres=OFF -DBUILD_opencv_cudalegacy=OFF -DBUILD_opencv_cudafilters=OFF -DBUILD_opencv_cudastereo=OFF -DBUILD_opencv_cudafeatures2d=OFF -DBUILD_opencv_shape=OFF -DBUILD_opencv_ml=OFF -DBUILD_opencv_stitching=OFF -DBUILD_opencv_python_bindings_generator=OFF -DBUILD_opencv_photo=OFF -DBUILD_opencv_cudaoptflow=OFF -DBUILD_opencv_ts=OFF -DBUILD_opencv_calib3d=OFF -DBUILD_opencv_videostab=OFF -DBUILD_opencv_cudacodec=OFF -DBUILD_opencv_core=ON -DBUILD_opencv_cudaimgproc=OFF -DBUILD_opencv_dnn=OFF -DBUILD_opencv_objdetect=OFF -DBUILD_opencv_apps=OFF -DBUILD_opencv_cudev=OFF -DBUILD_opencv_video=OFF -DBUILD_opencv_cudawarping=OFF -DBUILD_opencv_cudaarithm=OFF -DBUILD_opencv_features2d=OFF -DBUILD_opencv_cudaobjdetect=OFF -DBUILD_opencv_flann=OFF -DCMAKE_TOOLCHAIN_FILE=$CMAKE_TOOLCHAIN_FILE -DFFMPEG_LIBRARY_DIRS="/lib/aarch64-linux-gnu/" ..
RUN make -j8
RUN make install


WORKDIR /work
edit flag offensive delete link more
1

answered 2018-03-28 10:32:58 -0600

tomoaki0705 gravatar image

Let's separate the OpenCV problem and your configuration problem.

compiler

There's a very simple short code in OpenCV which checks if compiler accepts NEON. https://github.com/opencv/opencv/blob... what happens if you just try to compile this code ? no CMake, just type

aarch64-linux-gnu-g++ cpu_neon.cpp

what happens ?

environment

you are specifying CMAKE_TOOLCHAIN_FILE using $CMAKE_TOOLCHAIN_FILE variable. What is the contents of this variable ? Where is it setted ? is it pointing a correct file which actualy exists ?

sudo

In the issue comment, you show a command using "sudo cmake" why sudo ? sudo is only required for installing, never for cmake

compiler

Thanks for the detail docker, but where did you install the cross compiler ?

zip

Why are you making a symbolic link of opencv ?

ln -s /opencv/opencv-3.4.0 /opencv/opencv

what if you don't do this symbolic link part and directly work in the directory created by unzipping ?

BTW, why aren't you getting tar.gz instead of zip ?

And, why are you trying to build using docker ? It's way easier to build directly on real ARM 64bit devices. It's just a 40$ or so and you'll have much much less problems.

edit flag offensive delete link more

Comments

Hello, this website unfortunately severely limits talking back and forth. Here is my full answer https://gist.github.com/Nadav-Eyesigh...

NadavR gravatar imageNadavR ( 2018-03-29 01:56:05 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-03-28 10:08:49 -0600

Seen: 5,567 times

Last updated: May 13 '18