I have been struggling with this for days.
According to the several tries in http://www.pcl-users.org/,
there is no ‘official’ guide or package to compile it for android environment. Here is
PCL wiki describing how to compile, but I think it’s outdated.
On the other hand, there is a build script called ‘pcl-superbuild‘,
thanks to Pat
Marion. Unfortunately, it is outdated too. However, it has been greatly helpful to understand cross compiling and what should I need to compile PCL for compiling android successfully.
Since there seems no guide for windows environment with cmake-gui, I wrote this in simple steps for my sake. I compiled in windows x86, using cmake-gui(2.8.12).
Step 1. Run configuration with cmake-gui
Once run cmake-gui and configure, it will show a pop-up window to specify the generator. Choose compiler as MinGW
Makefiles and check Specify
toolchain file for cross-compiling.
For toolchain, choose toolchain-android.cmake in ./toolchains.
Step 2. Setting correct paths / filepaths
During the configuration, errors may occur. Make sure the paths/filepaths are correct. In my case, all I had to do was setting PYTHON_EXECUTABLE and GIT_EXECUTABLE.
Step 3. Setting build target
After serveral times of fixing errors and re-configuring, you would have entries below. I checked BUILD_ANDROID only.
When all entries are clear, then the output log would be like this:
Step 4. Compile and troubleshooting
After this, you may want to build it. Go to where the generated makefiles are located, and run make.
In my case, I run powershell and did like this (I will not explain options here):
From here, you may have several errors depends on your environment. I’ll list what I have faced and resolved. Some can be resolved before run make; some may not, as you should clone dependencies prior to fix it.
TROUBLESHOOTING 1. PROBLEM WITH ‘ISNAN‘ OR ‘ISFINITE’
If you have a problem with these, it might be a confliction between C99 and C++11 support. Edit ./build/CMakeCache.txt and set below flags will fix it. Here’s a refer.
TROUBLESHOOTING 2. INTERNAL COMPILER ERROR AT ‘NARF.CPP’ AND ‘NARF_KEYPOINT.CPP’
There are several reports regard on this
problem that using powf function
will cause the 4.7 gcc of the Android NDK to crash. One workaround is changing powf to std::pow.
TROUBLESHOOTING 3. PTHREAD RELATED PROBLEM ON COMPILING BOOST LIBRARY
If there is some kind of #error
“Sorry, no boost threads are available for this platform.” occurs, that probably be the conflict between boost and gcc
4.7. An old version of boost (1.45) is used here and in header file, it has no idea to proceed changed macro.
Add a flag in ./build/CMakeExternals/Source/boost/boost_1_45_0/boost/config/stdlib/libstdcpp3.hpp :
TROUBLESHOOTING 4. CMAKE ERROR – UNKOWN ARGUMENTS SPECIFIED
Got similar cases here,
but not sure why. A variable is not matched maybe? Apparently, it relates to gcc version (in my case, gcc 4.7). The error prints like:
if given arguments:
“arm-linux-androideabi-gcc.exe (GCC) 4.7
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software”
From my experience, there were two places where this error occurs; GenerateExportHeader.cmake and vtkCompilerExtras.cmake.
Both are in vtk’s cmake directory. Change those files
Running in android
Copy Boost/Flann/Eigen/PCL static libraries in ./build/CMakeExternals/Install. I created android application with sample JNI project in Pat Marion’s PCL repository. With a little bit of modification, I could get a result below (output was pcd, I converted to
ply to see in MeshLab):
Just one more thing. I was able to run it smoothly by changing Application.mk a
bit, such as:
APP_PLATFORM := gnustl_static (stlport_static won’t work)
C_FLAGS := -fpermissive -rtti (these may fix Boost problem)
That’s it. As a future work, I need to find out how to compile with recent PCL library (1.7.1 now) and make a demo running in android device.