I try to make kenlm binaries usable on Android. Kenlm is written in c++ and uses cmake, so I tried to do a toolchain file to crosscompile with cmake.
My toolchain file looks like that :
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_SYSTEM_VERSION 26)
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)
set(CMAKE_ANDROID_NDK "/home/marie/Android/Sdk/ndk/16.1.4479499")
set(BZIP2_LIBRARIES "/usr/lib/x86_64-linux-gnu")
set(LIBLZMA_LIBRARY "/usr/lib/x86_64-linux-gnu/liblzma.so")
set(LIBLZMA_LIBRARIES "/lib/x86_64-linux-gnu")
set(LIBLZMA_HAS_AUTO_DECODER TRUE)
set(LIBLZMA_HAS_EASY_ENCODER TRUE)
set(LIBLZMA_HAS_LZMA_PRESET TRUE)
set(ZLIB_LIBRARIES "/home/marie/Android/Sdk/ndk/16.1.4479499/platforms/android-26/arch-arm64/usr/lib")
and the CMakeLists.txt from kenlm
cmake_minimum_required(VERSION 2.6)
# Define a single cmake project
project(kenlm)
option(FORCE_STATIC "Build static executables" OFF)
if (FORCE_STATIC)
#presumably overkill, is there a better way?
#http://cmake.3232098.n2.nabble.com/Howto-compile-static-executable-td5580269.html
set(Boost_USE_STATIC_LIBS ON)
set_property(GLOBAL PROPERTY LINK_SEARCH_START_STATIC ON)
set_property(GLOBAL PROPERTY LINK_SEARCH_END_STATIC ON)
set(BUILD_SHARED_LIBRARIES OFF)
if (MSVC)
set(flag_vars
CMAKE_CXX_FLAGS CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE
CMAKE_CXX_FLAGS_MINSIZEREL CMAKE_CXX_FLAGS_RELWITHDEBINFO
CMAKE_C_FLAGS CMAKE_C_FLAGS_DEBUG CMAKE_C_FLAGS_RELEASE
CMAKE_C_FLAGS_MINSIZEREL CMAKE_C_FLAGS_RELWITHDEBINFO)
foreach(flag_var ${flag_vars})
if(${flag_var} MATCHES "/MD")
string(REGEX REPLACE "/MD" "/MT" ${flag_var} "${${flag_var}}")
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
else (MSVC)
if (NOT CMAKE_C_COMPILER_ID MATCHES ".*Clang")
set(CMAKE_EXE_LINKER_FLAGS "-static-libgcc -static-libstdc++ -static")
endif ()
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
endif ()
#Annoyingly the exectuables say "File not found" unless these are set
set(CMAKE_EXE_LINK_DYNAMIC_C_FLAGS)
set(CMAKE_EXE_LINK_DYNAMIC_CXX_FLAGS)
set(CMAKE_SHARED_LIBRARY_C_FLAGS)
set(CMAKE_SHARED_LIBRARY_CXX_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
set(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS)
endif ()
# Compile all executables into bin/
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
# Compile all libraries into lib/
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
if (NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release)
endif()
option(COMPILE_TESTS "Compile tests" OFF)
if (COMPILE_TESTS)
# Tell cmake that we want unit tests to be compiled
include(CTest)
enable_testing()
endif()
# Add our CMake helper functions
include(cmake/KenLMFunctions.cmake)
if(MSVC)
set(CMAKE_C_FLAGS "${CMAKE_CXX_FLAGS} /w34716")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /w34716")
endif()
# And our helper modules
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/modules)
# We need boost
find_package(Boost 1.41.0 REQUIRED COMPONENTS
program_options
system
thread
unit_test_framework
)
# Define where include files live
include_directories(
${PROJECT_SOURCE_DIR}
${Boost_INCLUDE_DIRS}
)
# Process subdirectories
add_subdirectory(util)
add_subdirectory(lm)
When i try to
cmake -DCMAKE_TOOLCHAIN_FILE="./cmake_toolchain.cmake" ..
I get that
...
Unable to find the requested Boost libraries.
Boost version: 1.65.1
Boost include path: /usr/include
Could not find the following Boost libraries:
boost_program_options
boost_system
boost_thread
boost_unit_test_framework
...
So i tried to add the boost dir in the toolchain file :
set(BOOST_LIBRARYDIR "/usr/lib/x86_64-linux-gnu")
And it workd for the boost libraries but another error pops
-- Boost version: 1.65.1
-- Found the following Boost libraries:
-- program_options
-- system
-- thread
-- unit_test_framework
-- chrono
-- date_time
-- atomic
...
-- Configuring done
WARNING: Target "kenlm_util" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "probing_hash_table_benchmark" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "query" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "fragment" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "kenlm" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "build_binary" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "kenlm_benchmark" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "lmplz" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "count_ngrams" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "kenlm_builder" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "filter" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "phrase_table_vocab" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "streaming_example" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
WARNING: Target "interpolate" requests linking to directory "/usr/lib/x86_64-linux-gnu". Targets may link only to libraries. CMake is dropping the item.
-- Generating done
I've been trying many things to make it work like set(LINK_DIRECTORIES), set(CMAKE_INCLUDE_PATH), set(Boost_LIBRARY_DIRS) (to add multiple boost dirs), set(KENLM_ROOT_DIR), set(KENLM_LIB), set(KENLM_UTIL_LIB), set(KENLM_INC)
Nothing worked, and i've been searching for a while know, so if you have some hints it would be great
-----------------------------------------------------------------------------------------------------------------------------------
**EDIT : I compiled boost for android but I dont succeed to do that with bzip2, I know have an error of this style **
-- Found BZip2: /usr/local/lib/libbz2.a (found version "1.0.8")
-- Looking for BZ2_bzCompressInit
-- Looking for BZ2_bzCompressInit - not found