1

For my Android application, I want to port a C++ code which needs libtiff.

I have downloaded sources of libtiff and I try to compile them to generate libtiff.so in different architectures :

  • arm64-v8a
  • armeabi-v7a
  • x86
  • x86_64

But all I have succeeded in is to generate a libtiff.dylib...

What can I do to generate .so instead of .dylib in the 4 previous architecture ?

Here are my command lines :

> cd libtiff
> mkdir install
> cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_INSTALL_PREFIX=install --enable-shared .
> make
> make install

Note: I'm on Mac and compilation stuff is not my favorite subject ^^

Bruno
  • 3,872
  • 4
  • 20
  • 37
  • Host compiler for MacOS creates binaries for MacOS (e.g. libraries have `.dylib` extension) . For produce binaries for other architectures, you need to perform **cross-compilation**. Find and install a *cross-compiler*, find [CMake toolchain](https://cmake.org/cmake/help/v3.18/manual/cmake-toolchains.7.html) for it (or write the toolchain by hands) and use this toolchain with `-D` option for `cmake`. – Tsyvarev Jul 06 '20 at 09:12
  • oh ok. Any suggestion for a cross-compiler perhaps ? – Bruno Jul 06 '20 at 09:20
  • Just google for it. E.g. "macos cross compile x86 cmake". – Tsyvarev Jul 06 '20 at 09:23
  • @Tsyvarev, I found a solution with cmake & ninja, but I can't post my answer – Bruno Jul 06 '20 at 14:03
  • Does your solution significantly differ from common cross compiling for Android SDK? E.g. like in that question: https://stackoverflow.com/questions/53385391/compiling-ffmpeg-for-android-on-mac. – Tsyvarev Jul 06 '20 at 15:17
  • yes, totally different – Bruno Jul 06 '20 at 15:55

1 Answers1

0

I've found a way to cross-compile this lib with Android tools.

Here are the command lines to generate, for example, the arm64-v8a version

> [CMAKE_BIN_PATH]/cmake -DANDROID_ABI=arm64-v8a -DCMAKE_BUILD_TYPE=Release -DANDROID_PLATFORM=android-21 -DANDROID_NDK=[NDK_PATH] -DCMAKE_INSTALL_PREFIX=install -DCMAKE_TOOLCHAIN_FILE=[NDK_PATH]/build/cmake/android.toolchain.cmake  -DCMAKE_MAKE_PROGRAM=[CMAKE_BIN_PATH]/ninja -G Ninja
> [CMAKE_BIN_PATH]/ninja
> [CMAKE_BIN_PATH]/ninja install

or, in a one-line version

> [CMAKE_BIN_PATH]/cmake -DANDROID_ABI=arm64-v8a -DCMAKE_BUILD_TYPE=Release -DANDROID_PLATFORM=android-21 -DANDROID_NDK=[NDK_PATH] -DCMAKE_INSTALL_PREFIX=install -DCMAKE_TOOLCHAIN_FILE=[NDK_PATH]/build/cmake/android.toolchain.cmake  -DCMAKE_MAKE_PROGRAM=[CMAKE_BIN_PATH]/ninja -G Ninja && [CMAKE_BIN_PATH]/ninja && [CMAKE_BIN_PATH]/ninja install

In details:

  • [CMAKE_BIN_PATH] is the path of cmake: /Library/Android/sdk/cmake/3.6.4111459/bin
  • [NDK_PATH] is the path of the NDK: /Library/Android/sdk/ndk-bundle
  • CMAKE_INSTALL_PREFIX is a flag to specify the install dir. In my case, I've decided to create the install dir in the libtiff dir
  • CMAKE_TOOLCHAIN_FILE: if a flag to specify the toolchain to use. Use the Android toolchain file inside the NDK dir, and not in the cmake dir
  • CMAKE_MAKE_PROGRAM is a flag to specify the path of ninja, located in the cmake dir
  • -G is the specify the build system generator, Ninja here
Bruno
  • 3,872
  • 4
  • 20
  • 37