Problems installing OpenCV 4.5.4 on aarch64

Installation of OpenCV 4.x on aarch64 for native compile was failing install while, I assume, trying to link videoio.
Berak’s comment to this original post suggested I look at the build bot for info. As far as I could see the build bot failed on every attempt to build for aarch64!

The output after previous make attempts suggested that Position Independent Code needs to be used and suggested recompile with -fPIC flag set. I searched for clues on this in the Opencv docs and tried cmake with -D ENABLE_PIC=ON. Same result ensued.

I then started wondering if it was something to do with FFmpeg as OpenCV 4.x install docs suggested use of ffmpeg v5.x. I started searching for “FFmpeg”, “-fPIC” and “aarch64” and came across various issues. That started me thinking that it wasn’t the OpenCV install processs that was generating the error but somehow FFmpeg was issuing warnings possibly from the linkage process. So after a fair bit of browsing of ffmpeg-trac issues, I got a good clue from #9612 (--enable-pic flag doesn't affect the object files from assembly) – FFmpeg .
I worked out how I thought I need to proceed to re-compile ffmpeg with aarch64 Position Independent Code.

I recompiled ffmpeg using the following:-

/configure --enable-shared --extra-cflags=“-fPIC” --enable-pic
make
sudo make install

The ffmpeg compilation took a while but after that finished, I tried a fresh install of OpenCV (without opencv_contrib, just to save time!). I set the following cmake flags:-

cmake -D CMAKE_BUILD_TYPE=RELEASE -D ENABLE_NEON=ON -D ENABLE_TBB=ON -D ENABLE_IPP=ON -D ENABLE_VFVP3=ON -D WITH_OPENMP=ON -D WITH_CSTRIPES=ON -D WITH_OPENCL=ON
-D ENABLE_CX11=ON -D ENABLE_PIC=ON -D BUILD_EXAMPLES=ON -D CMAKE_INSTALL_PREFIX=/usr/local …
make -j4
sudo make install

At last, compilation completed successfully this time. I have been able to compile and run my opencv modules that I have migrated from the 32 bit armv7 XU4, to the aarch64 N2+ platform. :grinning:

I think this leaves an open question, possibly against ffmpeg!
On Linux, if a later version of ffmpeg is required, apt install only gives earlier versions, v4.x? So ffmpeg has to be downloaded and compiled for that platform.
Should’nt ffmpeg recognize that if it is being compiled on aarch64 that the flags for PIC need to be implemented??
Someone out there may be more familiar with this.

2 Likes