Skip to content

Android: tell libtiff where libm is - #377

Open
jolavillette wants to merge 1 commit into
RetroShare:masterfrom
jolavillette:fix/android-tiff-find-libm
Open

Android: tell libtiff where libm is#377
jolavillette wants to merge 1 commit into
RetroShare:masterfrom
jolavillette:fix/android-tiff-find-libm

Conversation

@jolavillette

Copy link
Copy Markdown
Contributor

build_tiff fails at configure time, and takes build_cimg and build_phash
down with it:

-- Looking for pow
-- Looking for pow - not found
-- Looking for pow
-- Looking for pow - not found
CMake Error at FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find CMath (missing: CMath_pow)
Call Stack (most recent call first):
  cmake/FindCMath.cmake:51 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  CMakeLists.txt:156 (find_package)

tiff's cmake/FindCMath.cmake probes pow(3) twice — once with no extra
library, then again with whatever find_library(NAMES m) returned:

check_symbol_exists(pow "math.h" CMath_HAVE_LIBC_POW)
find_library(CMath_LIBRARY NAMES m)

if(NOT CMath_HAVE_LIBC_POW)
    set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} ${CMath_LIBRARY})
    check_symbol_exists(pow "math.h" CMath_HAVE_LIBM_POW)

On Android pow is in libm, and the NDK keeps libm.so under the API level
directory of the sysroot — sysroot/usr/lib/<triple>/<api>/ — which
andro_cmake does not add to CMAKE_LIBRARY_PATH; it sets it to ${PREFIX}/lib
only. So find_library returns NOTFOUND, CMAKE_REQUIRED_LIBRARIES gains
nothing, the second probe links exactly like the first one, and both fail with
undefined symbol: pow. Note the two identical Looking for pow - not found
lines in the output above: that pair is the signature of this bug.

Passing CMath_LIBRARY explicitly fixes it. The alternative — adding the API
level directory to the library search path in andro_cmake — would change how
the ten dependencies that already build resolve their libraries, for one
consumer.

Verified

build_tiff, build_cimg and build_phash all return 0, and the whole AAR now
builds: 42 MB, jni/arm64-v8a/libretroshare.so exporting JNI_OnLoad, the four
org.retroshare.service classes in classes.jar. Ubuntu 24.04, NDK
29.0.14206865, API level 24, arm64-v8a.

tiff cmake/FindCMath.cmake probes pow(3) twice, first with no extra
library then with the result of find_library(NAMES m). On Android pow is
in libm, and the NDK keeps libm.so under the API level directory of the
sysroot, sysroot/usr/lib/<triple>/<api>/, which andro_cmake does not add
to CMAKE_LIBRARY_PATH. find_library returns NOTFOUND, the second probe
links exactly like the first one and both fail with

  ld.lld: error: undefined symbol: pow

so configure aborts on

  Could NOT find CMath (missing: CMath_pow)

taking build_cimg and build_phash down with it.

Pass CMath_LIBRARY explicitly rather than adding the API level directory
to the search path of every dependency, which would change how the other
ten already working ones resolve their libraries.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant