Common problems when compiling a C/C++ source file for Android and how to fix them

Last Update: 21.09.2025/bs



Contents


  1. Common problems when compiling a C/C++ source file for Android and how to fix them
    1. Contents
    2. Introduction
    3. History
    4. General information
      1. Toolchains to compile C/C++ sourcecode for Android
      2. Patches for C/C++ programs or libraries
      3. Compiler parameter
      4. Missing definitions and functions
      5. Missing libraries
      6. Unnecessary libraries
      7. Dynamically linked binaries versus statically linked binaries
      8. Sample configure wrapper
      9. General trouble shooting hints
      10. How to list the compiler builtin macros
      11. How to print verbose make messages to STDOUT
      12. How to print verbose cmake messages to STDOUT
      13. How to print messages to STDOUT while compiling
      14. How to print messages to the Android log
      15. How to debug a binary in Android
      16. Functions and symbols defined in the standard Android OS libraries
      17. Examples for compiling C/C++ programs for Android
      18. Documentation for the compiler and tools
      19. General hints
    5. Specific errors
      1. ERROR: "cannot find crtbegin_dynamic.o: No such file or directory"
      2. ERROR: fatal error:sys/fcntl.h:No such file or directory
      3. ERROR: undefined reference to `getsubopt'
      4. ERROR: error: undefined reference to 'stderr'
      5. ERROR: faddrs.h: No such file or directory
      6. ERROR: ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
      7. ERROR: error: "./nmap": executable's TLS segment is underaligned: alignment is 8, needs to be at least 64 for ARM64 Bionic
      8. ERROR: ld: error: undefined symbol: index
      9. ERROR: ld: error: undefined symbol: rindex
      10. ERROR: ld: error: undefined symbol: strverscmp
      11. ERROR: use of undeclared identifier 'ushort'; did you mean 'short'?
      12. ERROR: use of undeclared identifier 'versionsort'
      13. ERROR: libutil.so missing
      14. ERROR: ld: error: undefined symbol: getdtablesize
      15. ERROR: the static libraries for building a static binary are missing
      16. ERROR: src/ls.c:2276:6: error: function-like macro '__GNUC_PREREQ' is not defined
      17. ERROR: unused DT entry: DT_RPATH (type 0xf arg 0xf7a)
      18. ERROR: cannot find entry symbol _start
      19. ERROR: non-root user can not create hard links
      20. ERROR: ld: error: unable to find library -lrt
      21. ERROR: ld: error: undefined reference due to --no-allow-shlib-undefined: wmempcpy
      22. ERROR: use of undeclared identifier 'nl_langinfo'
      23. ERROR: Pointer tag for 0xdbcd000000060106 was truncated
      24. ERROR: ld.lld: error: undefined symbol: __assert_fail
      25. ERROR: ld.lld: error: undefined reference: frexp
      26. How to define the value used by the marco  __BIONIC_AVAILABILITY_GUARD
      27. ERROR: openat-die.c:37:3: error: use of undeclared identifier 'error'
      28. ERROR: error: expected ')' in the statement __attribute__((__sentinel__(1)));
      29. ERROR: libintl.h not found
      30. ERROR: ld.lld: error: undefined symbol: bzero
      31. ERROR: ./include/fileutils.h:90:19: error: static declaration of 'close_range' follows non-static declaration
      32. ERROR: ld.lld: error: duplicate symbol: memcmp

 

Introduction


This page contains general information about compiling C/C++ programs for Android with clang or gcc. It also provides some tips for troubleshooting common problems when compiling a binary for Android.

Please note that all binaries or Magisk Modules mentioned in this documentation are for Android on arm64 CPUs.




History


ChangeLog

21.09.2025

inital release



----


Old changelog

27.11.2024

initial release

22.01.2025

added the infos for fixing the error use of undeclared identifier 'nl_langinfo'  

23.01.2025

added the infos about the error ERROR: Pointer tag for 0xdbcd000000060106 was truncated     

27.01.2025

added the infos about the error ERROR: ld.lld: error: undefined symbol: __assert_fail  

13.04.2025

added the infos about the error ERROR: ld.lld: error: undefined reference: frexp   

15.04.2025

added the infos about How to define the value used by the marco  __BIONIC_AVAILABILITY_GUARD  

19.04.2025

added the infos about the error ERROR: openat-die.c:37:3: error: use of undeclared identifier 'error'      

07.06.2025

added the infos about the error ERROR: error: expected ')' in the statement __attribute__((__sentinel__(1)));    
added the infos about the error ERROR: libintl.h not found   

15.06.2025

added the infos about the error ERROR: ld.lld: error: undefined symbol: bzero      

07.07.2025

updated the infos about the alignment error : The additional flags must be added to the LDFLAGS and NOT to the CFLAGS

24.08.2025

added the infos about the error duplicate definition of the function close_range  

19.02.2025

added the infos about the error ld.lld: error: duplicate symbol:       
updated the infos about the alignment error : The clang from the Android NDK must be version 29 or newer





General information




Toolchains to compile C/C++ sourcecode for Android


There are various ways to compile C/C++ programs for Android.

The "official" way is to use one of the Android NDKs from Google on a PC running Linux, Windows, or MacOS.

The Android NDKs are available here for download:

https://developer.android.com/ndk/downloads#stable-downloads

The Android NDKs contain everything needed to compile C or C++ programs for the Android OS.


Please note that there is only a clang compiler in the current version of the Android NDKs.

The last Android NDK with the gcc is the Android NDK r14b - that NDK version is still available for download on this page:

https://github.com/android/ndk/wiki/Unsupported-Downloads#r14b


Another method for compiling C/C++ programs is to use a compiler on your smartphone.


This can be done in Termux, for example. Termux is an almost complete Linux environment for Android that contains all the necessary tools and libraries for creating C/C++ programs on Android.
The disadvantage here, however, is that programs created under Termux use Termux's own configuration files and libraries and therefore only run to a limited extent on phones without Termux.


To get around this limitation, I created a Magisk module that contains the clang compiler (clang version 19) and the files from the Android NDK. The binaries created with the compiler from this Magisk module should run on any phone.

The documentation for the Magisk Module with clang19 is here:

Documentation for the Magisk Module with clang19 and the NDK r27b


The Magisk Module is available here: 

http://bnsmb.de/files/public/Android/clang19_19.0.0git-v1.2.2.zip

The files from this Magisk Module are also available in a GitHub repository:

https://github.com/bnsmb/Magisk-Module-with-clang19

Note that I have also created several other Magisk modules (with cmake, gdb, git, etc) that may be useful for compiling C/C++ programs on smartphones. See this page for a list of Magisk Modules that I have created.


There is also a Magisk Module with the gcc :

The gcc in this GCC toolchain is version gcc 10.2 and the libraries in the GCC toolchain come from the Android API version 21, which are both quite old.

This Magisk Module is available here:

https://github.com/Googlers-Repo/gcc/



For those who do not use Magisk on their smartphone or do not have root privileges, I have also created a tar archive with a clang19 toolchain that installs in /data/local/tmp on the phone and can be used by the user shell (the default user for adb sessions).

This clang19 toolchain contains the clang compiler, the necessary files from the Android NDK, and other tools needed to compile C/C++ programs (including the debugger gdb)

As of 21.09.2025 the clang19 toolchain contain these programs:

List of programs in the clang19 toolchain
# The tools included in the tar file with the clang19 toolchain are:
#
# clang 19.0.0
# cmake 4.0.1
# ninja 1.12.1 and 1.13.1
# make 4.4.1
# meson 1.7
# binutils 2.44 (addr2line  ar  as  c++filt  elfedit  gprof  ld  ld.bfd  nm  objcopy  objdump  ranlib  readelf  size  strings  strip)
#
# autoconf 2.72
# automake 1.17
# m4 1.4.20
# libtool 2.5.3
# patch 2.8 (gnupatch)
# patchelf 0.18
# GNU help2man 1.49.3
# pkg-config 0.29
# pkgconf 2.30
# autopoint 0.23
# texinfo 7.2
#
# bash 5.2.37
#
# bison 3.8
# flex 2.6.4
#
# gdb 16.3 (dynamically and statically linked binaries)
#
# rsync 3.4.1
#
# wget 2.1.0
# curl 8.13.0
#
# perl 5.40
# python 3.14
# pip 25.0.1
# tcl 9.0
# sqlite3 3.50.1
#
# sshd/ssh 10.0p2
#
# git 2.49
#
# gpg 1.4.3
#
# dig 9.11.37
#
# nano 8.6 and nano 6.4
# vim 9.1-672
# ed 1.21
# bvi /bmore 1.5.0
#
# man 2.13
#
# tmux 3.5a
#
# tar 1.35
# dd 9.5.58
#
# jq 1.7.1
#
# gawk 5.3.2
# grep 3.12
# gsed 4.9
# diff 3.11
# bc 1.08.2
# less 679
# htop 3.4.1
# btop 1.4.4 (btop needs root access)
#
# Android SDK build tools 35.0.2 (aidl zipalign aapt aapt2 dexdump split-select e2fsdroid sqlite3 fastboot sload_f2fs hprof-conv etc1tool mke2fs make_f2fs adb make_f2fs_casefold veridex)
# ( the binaries are from this ZIP file: https://github.com/lzhiyong/android-sdk-tools/releases/download/35.0.2/android-sdk-tools-static-aarch64.zip )
#
# OpenVPN 2.7 (openvpn requires root access)
#
# unfsd 0.11.0 (a userland NFS daemon usable by non-root user; the default exports file for this binary is /data/local/tmp/sysroot/etc/exports)
#
# protoc v32.1.0 (currently the binary only)
#
# various compression tools:
#
# 7zz 25.00
# bzip2 1.0.8
# zip 3.0
# unzip 5.52
# lz4 v1.10.0
# lzop 1.04
# compress 5.0
# uncompress 5.0
# zstd 1.5.6
# pigz 2.8
# xz 5.8.1
# gunzip 1.13
# gzip 1.13
# unrar 5.91
# lzip 1.25
#



see How to install a Toolchain for clang on phones without root access for the documentation for the clang19 toolchain.


The clang19 toolchain is available here for download:

http://bnsmb.de/files/public/Android/clang19_toolchain-v1.5.0_release_21.09.2025_.tar.gz

The files from the clang19 toolchain are also available in a repository on GitHub:

https://github.com/bnsmb/clang19_toolchain_for_android


Notes

I recommend using the clang19 toolchain for compiling C/C++ programs on smartphones.


The URLs in this page are current as of 21.09.2025.

The URLs in this page for the Magisk Moduls and the tar file change with new versions.
If a link no longer works, please check the list of my Magisk Modules or the file list on the web server for a newer version:



Patches for C/C++ programs or libraries


The file system structure in Android differs from the standard file system structure in Linux. Therefore, the source code for most programs that use configuration files in a location common in Linux must be adapted for Android.

To avoid reinventing the wheel, it is advisable to check whether there are already patches in Termux for the program to be compiled. The patches from Termux can usually be applied without further changes after correcting the directory name in the patches.

Since the patches in Termux also contain other changes that are necessary for Android, it is definitely advisable to take a look at the patches before compiling.

The patches from Termux for Unix programs can be found here:

https://github.com/termux/termux-packages/tree/master/packages/




Compiler parameter


When compiling C/C++ programs for Android these compiler and linker flags are mandatory for dynamically linked binaries:

CFLAGS="${CFLAGS} -fPIE -fPIC"

LDFLAGS="${LDFLAGS} -pie"


Some configure scripts only use the CFLAGS variable for the compiler options to compile and build a test program, causing the configure script to fail because the linker option -pie is missing. To work around this, add the parameter -pie to CFLAGS before running the configure script.

Note that option -pie is not allowed for creating libraries.


Many source codes for Unix programs use code that is no longer permitted in clang by default. However, this code is still okay and working

To ensure that clang ignores most of these errors in the source code and still compiles the program, I use these compiler flags

CFLAGS="${CFLAGS} -Wno-implicit-function-declaration -Wno-int-conversion"


To create a binary with all info necessary for using a debugger like gdb, use these compiler flags:

DEBUG_CFLAGS="-g -O0"

CFLAGS="${CFLAGS} ${DEBUG_FLAGS}"



Missing definitions and functions


There are a lot of definitions used in the source code of existing Unix programs that do not exist in Android. For many of them, workarounds for compiling under Android can be created relatively easily.

I have created an include file with the missing definitions that I have found so far when compiling C programs in Android. The include file can be found here: add_missing_definitions.h



As of 19.09.2025 there are these definitions in the file:

// This file defines
//   quad_t
//   u_quad_t
//   short
//
// This file defines the functions
//   strverscmp
//   versionsort
//   getdtablesize
//   index
//   rindex
//   catopen
//   catgets
//   catclose
//   nl_langinfo
//   getpwent
//   endpwent
//   CloseSocket
//   mktime_z
//   bzero
//
// This file defines the macros
//
//   __GNUC_PREREQ
//   isblank
//   min
//   max
//



In most cases, you cannot include this file without editing it - see the comment in the header of the include file:

// Please note that you must remove the definitions for functions that already exist in the source code from this include file.
// If not, error messages like this are displayed when compiling your source code:
//
//    command.c:(.text+0x348): multiple definition of `catclose'
//    array.o:array.c:(.text+0x348): first defined here
//
// Therefore, either edit this file before using it or copy only the necessary parts to your source files
//


Notes

The include file is also available in my GitHub repository with include files and libraries for Android:

https://raw.githubusercontent.com/bnsmb/libraries-and-include-files-for-Android-on-arm64-CPUs/refs/heads/main/sysroot/usr/include/add_missing_definitions.h




Missing libraries


The NDK for Android only contains some of the standard include files and libraries for Linux. If one of the standard include files is missing, check the sysroot from another NDK version to see if it contains the missing file.


I've created a GitHub repository with some of the standard non-OS libraries required by Unix programs:

https://github.com/bnsmb/libraries-and-include-files-for-Android-on-arm64-CPUs

This repository contains include files, and static and dynamic libraries for Android running on arm64 CPUs.

Please note that I have not checked whether patches are required for Android for most of the libraries in this repository.

The purpose of these libraries is to enable you to compile a binary without errors. Before using the libraries for productive binary files, you should therefore compile your own versions of the neccessary libraries for your binary after applying the necessary patches.



Unnecessary libraries


The configuration scripts and makefiles for some Unix programs require libraries that are not needed in the Android environment and are not available there.

This applies, for example, to the library libpthread.so: The functions from this library are included in the standard OS libraries in Android.

To avoid having to manually adjust the configure scripts and makefiles, it makes sense to create an empty dummy library with the name libpthread.so.

This can be done as follows (after initializing the clang19 toolchain with "source bin/init_clang19_env" )

cat<<EOT >foo.c
// foo.c  - make sure to use a unique name for this dummy function!
int __bs_function_42() {
    return 42;
}

EOT

$CC -fPIE -fPIC -c foo.c

$AR rcs libpthread.a foo.o

$CC $LDFLAGS -shared -o libpthread.so foo.o


The commands create a library for static builds (libpthread.a) and a library for dynamic builds (libpthread.so); $CC and $AR must contain the name of the executables that are used to create binaries for Android, e.g:

[aarch64-linux-android] [ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/source/dummyLib/test ] $ echo $CC
/data/develop/android/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android29-clang
[aarch64-linux-android] [ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/source/dummyLib/test ] $

[aarch64-linux-android] [ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/source/dummyLib/test ] $ echo $AR
/data/develop/android/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/bin/llvm-ar
[aarch64-linux-android] [ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/source/dummyLib/test ] $


The environment variable $LDFLAGS in this example must contain the necessary linker parameter, example:

[clang19 toolchain] ASUS_I006D:/data/local/tmp $ echo $LDFLAGS
-L/data/local/tmp/sysroot/usr/lib -L/data/local/tmp/sysroot/usr/ndk/r27d/sysroot/usr/lib/aarch64-linux-android/31 -L/data/local/tmp/sysroot/usr/ndk/r27d/sysroot/usr/lib/aarch64-linux-android -L/data/local/tmp/develop/sysroot/usr/lib -B/data/local/tmp/sysroot/usr/ndk/r27d/sysroot/usr/lib/aarch64-linux-android/31/ --sysroot=/data/local/tmp/sysroot/usr/ndk/r27d/sysroot -lc
[clang19 toolchain] ASUS_I006D:/data/local/tmp $


Please note that the dummy library is then also required to execute the binary file. To avoid this, delete the linker parameter for the library, -lpthread in this example, in the Makefile instead of using a dummy library before creating the binary file. Or create a statically linked binary using the static library libpthread.a.


Dynamically linked binaries versus statically linked binaries


Unix programs can be either dynamically or statically linked. Most configure scripts for Unix programs create makefiles to build dynamically linked binaries by default, but also support the building of statically linked binaries.

Both methods have advantages and disadvantages (for more information, see Building Dynamically Linked Binaries for Android Using C or C++)


Since statically linked binary files cannot use hostname resolution in Android, I recommend creating dynamically linked binary files, but only for the standard Android OS libraries, e.g.:
 
[clang19 toolchain] ASUS_I006D:/data/local/tmp/sysroot/usr/bin $ file $PWD/wget2
/data/local/tmp/sysroot/usr/bin/wget2: ELF shared object, 64-bit LSB arm64, dynamic (/system/bin/linker64), for Android 28, built by NDK r25 (8775105), stripped
[clang19 toolchain] ASUS_I006D:/data/local/tmp/sysroot/usr/bin $

[clang19 toolchain] ASUS_I006D:/data/local/tmp/sysroot/usr/bin $ ldd $PWD/wget2

    linux-vdso.so.1 => [vdso] (0x7d96df3000)
    libdl.so => /apex/com.android.runtime/lib64/bionic/libdl.so (0x7d915cd000)
    libc.so => /apex/com.android.runtime/lib64/bionic/libc.so (0x7d91602000)
[clang19 toolchain] ASUS_I006D:/data/local/tmp/sysroot/usr/bin $


Binaries compiled this way should run on any Android OS.



Sample configure wrapper


I use this template for a wrapper script for configure to create makefiles for compiling Unix binaries:

[clang19 toolchain] ASUS_I006D:/data/local/tmp/sysroot $ cat myconfigure
#
# template file with ./configure command for using with the clang19 tool chain
#
#

# use these addtional CFLAGs for binaries should be executed using a debugger like gdb
#
#DEBUG_CFLAGS="-g -O0"

DEBUG_CFLAGS=""

# these configure options are required to compile the source code of a lot of  "old" unix programs with clang
#
CFLAGS="${CFLAGS} -Wno-implicit-function-declaration -Wno-int-conversion ${DEBUG_CFLAGS}"


# add additional CFLAGS for the compiler here
#
CFLAGS="${CFLAGS} "

# C++ compiler options
#
CXXFLAGS="${CFLAGS}"

# add additional LDFLAGS for the linker here
#
LDFLAGS="${LDFLAGS} "


# add additional configure options here (either one per line or multiple options on one line)
#
CONFIGURE_OPTIONS="
"

# target directory used by "make install"
#
TARGET_ROOT="${TARGET_ROOT:=/data/local/tmp/develop/sysroot}"

#
# set PREFIX to "echo" or something similar before calling this script to run it in dry-run mode
#
${PREFIX}  ./configure  --prefix=${TARGET_ROOT}/usr/ CFLAGS="${CFLAGS}" LDFLAGS="${LDFLAGS}" ${CONFIGURE_OPTIONS} $*

[clang19 toolchain] ASUS_I006D:/data/local/tmp/sysroot $



General trouble shooting hints


This section contains general hints for trouble shooting compile errors.



How to list the compiler builtin macros


To print all gcc or clang builtin Macros use the command

$CC  -dM -E - < /dev/null

(where $CC is the compiler used - either gcc or clang)



How to print verbose make messages to STDOUT


Use the parameter

V=1

or

VERBOSE=1

for make to enable verbose compile messages



How to print verbose cmake messages to STDOUT


Use the parameter

-DCMAKE_VERBOSE_MAKEFILE=ON

for cmake to enable verbose make messages

 

How to print messages to STDOUT while compiling


To instruct the preprocessor to print messages while compiling C source files, these instructions can be used:

#pragma message "Compiling my program..."

#warning "This is just a test warning"

#ifndef MY_DEFINE
    #error "MY_DEFINE is not set!"
#endif

Note that the compile fails after printing the error message!



How to print messages to the Android log


To print a message into the Android log (logcat) from an C/C++ program while executing the programm use these instructions


#ifdef __ANDROID__
#include <android/log.h>
#endif

/*
 

 "ANDROID_LOG_INFO" is the priority for the log message

  see the file

   ./sysroot/usr/include/android/log.h

  in the Android NDK for other log priorities
 
 "btop" can be any string to distinguish the messages in logcat

 "val" is the variable to print in this example

 "debut: value=%d" is the string to print to logcat


*/

#ifdef __ANDROID__
__android_log_print(ANDROID_LOG_INFO, "btop", "debug: value=%d", val);
#endif


and add the log library to the LDFLAGS:

LDFLAGS += -llog


To view the messages when executing the program use this command:

logcat -s btop

or print only messages with the priority Info and higher:

logcat btop:I* *:S


e.g.:

[clang19 toolchain] ASUS_I006D:/data/local/tmp/sysroot $ logcat -d -s btop
--------- beginning of main
09-20 10:26:28.281 17652 17652 I btop    : debug: value=55555
09-20 10:32:46.376 18060 18060 I btop    : debug: value=6666
09-20 10:33:25.832 18075 18075 I btop    : debug: value=6666
[clang19 toolchain] ASUS_I006D:/data/local/tmp/sysroot $

[clang19 toolchain] ASUS_I006D:/data/local/tmp/sysroot $ logcat -d btop:I* *:S
--------- beginning of main
09-20 10:26:28.281 17652 17652 I btop    : debug: value=55555
09-20 10:32:46.376 18060 18060 I btop    : debug: value=6666
09-20 10:33:25.832 18075 18075 I btop    : debug: value=6666
[clang19 toolchain] ASUS_I006D:/data/local/tmp/sysroot $




How to debug a binary in Android


To debug a program in Android on the phone use the debugger gdb (gdb is part of the clang19 toolchain; the statically linked gdb binary is also available here: http://bnsmb.de/files/public/Android/binaries_for_arm64/static_gdb/)


Use the parameter -tui for the text user interface:

gdb -tui  bvi 




Notes

The warning messages about missing sections in the standard OS libraries can be ignored.

see https://sourceware.org/gdb/documentation for the documentation for gdb.

Do not add the parameter for the program to debug in the gdb command line; add the parameter for the program after the gdb command run.

It's recommended to compile the binary with the compiler options for debugging support in this case



Functions and symbols defined in the standard Android OS libraries


Not all standard functions and symbols defined in the standard OS libraries of Linux are also defined in the standard libraries for Android.
Some standard functions are only defined in the standard libraries for Android from a certain Android version onwards.

To test in which version of Android a function is defined, the following command can be used:

Check in which Android version the function __fpending is defined:

[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/android-ndk-r25.2/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib ] $ for i in ./aarch64-linux-android/*/libc.so ; do echo "** $i:" ;  nm $i | grep  __fpending ; done
** ./aarch64-linux-android/21/libc.so:
** ./aarch64-linux-android/22/libc.so:
** ./aarch64-linux-android/23/libc.so:
00000000000180c8 T __fpending
** ./aarch64-linux-android/24/libc.so:
00000000000190c8 T __fpending
** ./aarch64-linux-android/26/libc.so:
000000000001a0c8 T __fpending
** ./aarch64-linux-android/27/libc.so:
000000000001a0c8 T __fpending
** ./aarch64-linux-android/28/libc.so:
000000000001c0c8 T __fpending
** ./aarch64-linux-android/29/libc.so:
000000000001c0c8 T __fpending
** ./aarch64-linux-android/30/libc.so:
000000000001d0c8 T __fpending
** ./aarch64-linux-android/31/libc.so:
000000000001e0c8 T __fpending
** ./aarch64-linux-android/32/libc.so:
000000000001e0c8 T __fpending
** ./aarch64-linux-android/33/libc.so:
000000000001e0c8 T __fpending
[aarch64-linux-android] [ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/android-ndk-r25.2/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib ] $


-> The symbol __fpending is defined in the libc.so from the API version 23 and newer.

Be aware, that a program compiled with the libc.so from the API version 23 will only work on Android compiled with API version 23 or newer (API version 23 is Android 6.0)

The list of the API versions for the various Android versions is available here:  https://source.android.com/docs/setup/reference/build-number 

The nm binary for this check can be the standard nm binary for Linux.



Examples for compiling C/C++ programs for Android


Find below a list of examples with instructions to compile C/C++ programs for Androd using the different methods.


Examples for compiling C/C++ programs with the GCC or clang from the Android NDK on the PC

Examples for compiling C programs for Android using gcc or clang  

How to compile python3 in Android using the GCC toolchain


Examples for compiling C/C++ programs in Termux on the phone

Compiling C programs in Android in Termux  

How to compile Perl for Android in Termux


Examples for compiling C/C++ programs with the GCC from the Magisk Module on the phone

Compiling C programs in Android using gcc


Examples for compiling C/C++ programs with the clang from the clang19 toolchain on the phone

How to compile Perl in Android with the clang19 toolchain on the phone

How to compile bash in Android with the clang19 toolchain on the phone  

How to compile jq in Android wit the clang19 toolchain on the phone

How to compile nano in Android with the clang19 toolchain on the phone



Documentation for the compiler and tools


Some documentation for the compiler and tools can be found here:


URL
Content
Comment
https://clang.llvm.org/docs/DiagnosticsReference.html
documentation for the diagnostic flags from clang




https://devhints.io/makefile
make file cheat sheet

https://gist.github.com/rueycheng/42e355d1480fd7a33ee81c866c7fdf78
another make file cheat sheet




https://cmake.org/cmake/help/latest/manual/cmake.1.html
documentation for the parameter of cmake




https://sourceware.org/gdb/current/onlinedocs/gdb.html/
documentation for the debugger gdb










General hints


A list of common problems and solutions for compiling with the Android NDK is here: https://developer.android.com/ndk/guides/common-problems  


To avoid problems because of invalid settings for the script ./configure it's recommended to delete all cache files before starting ./configure, e.g:

xtrnaw7@fedora01:/data/develop/android/source/ngrep-1.47$ find . -name config.cache -ls
    19970      1 -rw-r--r--   1 xtrnaw7  xtrnaw7         0 Feb 19 08:19 ./regex-0.12/config.cache
xtrnaw7@fedora01:/data/develop/android/source/ngrep-1.47$


# delete the config.cache files
#
find . -name config.cache -exec rm {} \;

# check:
#
find . -name config.cache -ls



Specific errors


Below is a list of errors I have encountered so far when compiling C/C++ programs for Android, including information on how to fix them.



ERROR: "cannot find crtbegin_dynamic.o: No such file or directory"


If clang complains about missing runtime libraries like this:

ERROR: "cannot find crtbegin_dynamic.o: No such file or directory" or "cannot find crtend_android.o: No such file or directory"

check that the LDFLAGS contain the parameter -B with the correct value, e.g:

-B/data/local/tmp/sysroot/usr/ndk/r27d/sysroot/usr/lib/aarch64-linux-android/31/

The directory must contain these files:

[clang19 toolchain] ASUS_I006D:/data/local/tmp/test $ ls  -l /data/local/tmp/sysroot/usr/ndk/r27d/sysroot/usr/lib/aarch64-linux-android/31/crt*o
-rw-r--r-- 1 shell shell  784 2025-08-03 12:22 /data/local/tmp/sysroot/usr/ndk/r27d/sysroot/usr/lib/aarch64-linux-android/31//crt_pad_segment.o
-rw-r--r-- 1 shell shell 3904 2025-08-03 12:22 /data/local/tmp/sysroot/usr/ndk/r27d/sysroot/usr/lib/aarch64-linux-android/31//crtbegin_dynamic.o
-rw-r--r-- 1 shell shell 3648 2025-08-03 12:22 /data/local/tmp/sysroot/usr/ndk/r27d/sysroot/usr/lib/aarch64-linux-android/31//crtbegin_so.o
-rw-r--r-- 1 shell shell 3720 2025-08-03 12:22 /data/local/tmp/sysroot/usr/ndk/r27d/sysroot/usr/lib/aarch64-linux-android/31//crtbegin_static.o
-rw-r--r-- 1 shell shell  840 2025-08-03 12:22 /data/local/tmp/sysroot/usr/ndk/r27d/sysroot/usr/lib/aarch64-linux-android/31//crtend_android.o
-rw-r--r-- 1 shell shell  840 2025-08-03 12:22 /data/local/tmp/sysroot/usr/ndk/r27d/sysroot/usr/lib/aarch64-linux-android/31//crtend_so.o
[clang19 toolchain] ASUS_I006D:/data/local/tmp/test $


If adding the parameter -B to the LDFLAGS does not fix the error, copy the crt*.o files to the working directory. That are the files

crtbegin_dynamic.o 
crtbegin_so.o 
crtbegin_static.o 
crtend_android.o 
crtend_so.o


In the clang19 toolchain is an alias for the necessary copy command:

[clang19 toolchain] 1|ASUS_I006D:/data/local/tmp/test $ alias cp_crt_libs
cp_crt_libs='cp ${NDK_DIR}/sysroot/usr/lib/${CPU_TYPE}-linux-android/${API}/crt*.o .'
[clang19 toolchain] ASUS_I006D:/data/local/tmp/test $



ERROR: fatal error:sys/fcntl.h:No such file or directory


Solution:

Use the headers

#include <fcntl.h>
#include <asm-generic/fcntl.h

 

ERROR: undefined reference to `getsubopt'


Solution:

Use a newer API version: getsubopt is defined in libc.so for android-26 and newer, but not for earlier platforms:

trnaw7@fedora01:/data/develop/android/source/libnl-3.9.0$ cd /data/develop/android/android-ndk-r25.2/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/
xtrnaw7@fedora01:/data/develop/android/android-ndk-r25.2/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib$

xtrnaw7@fedora01:/data/develop/android/android-ndk-r25.2/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib$ for i in ./aarch64-linux-android/*/libc.so ; do echo "** $i:" ;  nm $i | grep  getsubopt ; done
** ./aarch64-linux-android/21/libc.so:
** ./aarch64-linux-android/22/libc.so:
** ./aarch64-linux-android/23/libc.so:
** ./aarch64-linux-android/24/libc.so:
** ./aarch64-linux-android/26/libc.so:
000000000001c440 T getsubopt
** ./aarch64-linux-android/27/libc.so:
000000000001c440 T getsubopt
** ./aarch64-linux-android/28/libc.so:
000000000001e450 T getsubopt
** ./aarch64-linux-android/29/libc.so:
000000000001e450 T getsubopt
** ./aarch64-linux-android/30/libc.so:
000000000001f450 T getsubopt
** ./aarch64-linux-android/31/libc.so:
0000000000020450 T getsubopt
** ./aarch64-linux-android/32/libc.so:
0000000000020450 T getsubopt
** ./aarch64-linux-android/33/libc.so:
0000000000020450 T getsubopt
xtrnaw7@fedora01:/data/develop/android/android-ndk-r25.2/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib$



ERROR: error: undefined reference to 'stderr'


Solution: 

The most likely reason for error messsages like this

scanner.c:(.text+0x8c): undefined reference to `stdin'
scanner.c:(.text+0x90): undefined reference to `stdin'
scanner.c:(.text+0xbc): undefined reference to `stdout'
scanner.c:(.text+0xc0): undefined reference to `stdout'
/data/develop/android/android_root/usr/lib/libpcap.a(scanner.o): In function `yy_fatal_error':
scanner.c:(.text+0x259c): undefined reference to `stderr'
scanner.c:(.text+0x25a0): undefined reference to `stderr'

is that you built for android-23+ but the lib used has a minSdkVersion below that.


Credits: https://stackoverflow.com/questions/51767214/android-studio-with-ndk-link-error-undefined-reference-to-stderr



ERROR: faddrs.h: No such file or directory


Solution:

Use a more current API -- the file ifaddrs.h was added to Android in API 24. The file is only available in the sysroot for clang.



ERROR: ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]


Solution:

Add the option -Wno-implicit-function-declaration to the environment variable CFLAGS before executing ./configure:

export CFLAGS="$CFLAGS -Wno-implicit-function-declaration"



ERROR: error: "./nmap": executable's TLS segment is underaligned: alignment is 8, needs to be at least 64 for ARM64 Bionic


Executing a binary on the phone aborts with an error message like this:

ASUS_I006D:/data/local/tmp $  ./nmap
error: "./nmap": executable's TLS segment is underaligned: alignment is 8, needs to be at least 64 for ARM64 Bionic
Aborted
134|ASUS_I006D:/data/local/tmp $

Solution:

Either add the LDFLAGS 

-ffunction-sections -fdata-sections -Wl,--gc-sections

and rebuild the binary or correct the alignment using the script align_fix.py, e.g.:

[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/source/nmap-7.93 ] $ ../align_fix.py ./nmap
Found TLS segment with align = 8
TLS segment is underaligned, patching
[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/source/nmap-7.93 ]

The source for the script align_fix.py was copied from this webpage: https://stackoverflow.com/questions/72496162/how-to-cross-compile-kernel-exec-tools-for-android


Note that the python script align_fix.py might not change all necessary alignments in the binary - in this case re-link the binary using the additional options listed above.


If you are using the clang compiler from the Android NDK toolkit, make sure you are using aarch64-linux-android29-clang++ or a newer version



ERROR: ld: error: undefined symbol: index


Solution:

The index() function is used in old C programs but is now obsolete. The modern equivalent of index() is the strchr() function.

To fix the error replace index with strchr, example

// old line:
char *pos = index(string, char);

// new line:
char *pos = strchr(string, char);



ERROR: ld: error: undefined symbol: rindex


Solution:

The rindex() function is used in old C programs but is now obsolete. The modern equivalent of rindex() is the strrchr() function.

To fix the error replace rindex with strrchr.



ERROR: ld: error: undefined symbol: strverscmp


The function strverscmp is not defined in the file string.h in Android

Solution:

Add the definition of the function to the source file using it; a simple version of that function (which is not 100% compatibel!) is:

int strverscmp(const char *s1, const char *s2) { return strcmp(s1, s2); }



ERROR: use of undeclared identifier 'ushort'; did you mean 'short'?


Solution:

Either replace ushort with

unsigned short var;

or add a definition for ushort:

typedef unsigned short ushort;



ERROR: use of undeclared identifier 'versionsort'


Solution:

Add the missing function versionsort to the source code; an implementation of this function can be found here.



ERROR: libutil.so missing


Solution

libutil.so is not necessary in Android, all functions in that library are in the standard libc library in Android. To get around this error create a dummy library.




ERROR: ld: error: undefined symbol: getdtablesize


The function getdtablesize() retrieves the maximum number of file descriptors that a process can have open at any time. In Linux-based systems (including Android), it is not always available directly and is often replaced by other methods to achieve the same result.

Solution:

To replace it in programs for Android, this code can be used:

#include <unistd.h>
long open_max = sysconf(_SC_OPEN_MAX);



ERROR: the static libraries for building a static binary are missing


Workaround

If the static libraries for compiling a static binary are missing, they can be created from the dynamic library using the tools objcopy and ar.

However, recompiling the library as a static library from source is the more stable approach, especially since dynamic libraries often rely on dynamic linking mechanisms incompatible with static libraries.

Example

ASUS_I006D:/data/adb/modules/gcc_on_android/system/usr/share/gcc/aarch64-linux-android/lib # ls -l libm.*
-rw-r--r-- 1 root root 74520 2024-10-27 15:02 libm.so
ASUS_I006D:/data/adb/modules/gcc_on_android/system/usr/share/gcc/aarch64-linux-android/lib #

ASUS_I006D:/data/adb/modules/gcc_on_android/system/usr/share/gcc/aarch64-linux-android/lib # /system/usr/bin/objcopy --extract-symbol libm.so
ASUS_I006D:/data/adb/modules/gcc_on_android/system/usr/share/gcc/aarch64-linux-android/lib #

ASUS_I006D:/data/adb/modules/gcc_on_android/system/usr/share/gcc/aarch64-linux-android/lib # /system/usr/bin/ar rcs libm.a libm.so
WARNING: linker: Warning: "/system/usr/bin/ar" unused DT entry: DT_RPATH (type 0xf arg 0x3e1) (ignoring)
ASUS_I006D:/data/adb/modules/gcc_on_android/system/usr/share/gcc/aarch64-linux-android/lib #

ASUS_I006D:/data/adb/modules/gcc_on_android/system/usr/share/gcc/aarch64-linux-android/lib # ls -l libm*
-rw-r--r-- 1 root root 77108 2024-10-27 15:14 libm.a
-rw-r--r-- 1 root root 74520 2024-10-27 15:14 libm.so
ASUS_I006D:/data/adb/modules/gcc_on_android/system/usr/share/gcc/aarch64-linux-android/lib #

ASUS_I006D:/data/adb/modules/gcc_on_android/system/usr/share/gcc/aarch64-linux-android/lib # file libm.a libm.so
libm.a:  ar archive
libm.so: ELF shared object, 64-bit LSB arm64, static, not stripped
ASUS_I006D:/data/adb/modules/gcc_on_android/system/usr/share/gcc/aarch64-linux-android/lib #



ERROR: src/ls.c:2276:6: error: function-like macro '__GNUC_PREREQ' is not defined


Solution

Answer from ChatGPT:

__GNUC_PREREQ is a macro typically used in GNU-compatible compilers to check for specific GCC (GNU Compiler Collection) version requirements, but it's not always available in non-GCC or non-standard environments.


Define __GNUC_PREREQ Manually: If you're not using GCC, you can define this macro conditionally in your code to check for GNU versions only when __GNUC__ is defined:

#ifndef __GNUC_PREREQ
#define __GNUC_PREREQ(maj, min) ((__GNUC__ > (maj)) || (__GNUC__ == (maj) && __GNUC_MINOR__ >= (min)))
#endif



ERROR: unused DT entry: DT_RPATH (type 0xf arg 0xf7a)


Solution:

Answer from ChatGPT:

The message unused DT entry: DT_RPATH is a linker warning indicating that the specified RPATH in the ELF binary is not used by the dynamic linker. The RPATH (runtime library search path) is an embedded path that helps locate shared libraries when executing the binary, but if it doesn't match any needed paths, it's considered "unused."

This warning usually doesn't affect functionality but can be resolved by adjusting the linking options. Here are some ways to address it:

    Use DT_RUNPATH instead of DT_RPATH: Adding -Wl,--enable-new-dtags to your linker options will replace DT_RPATH with DT_RUNPATH, which is more modern and can be overridden by the environment variable LD_LIBRARY_PATH.

    Remove the RPATH: If the RPATH is unnecessary, you can remove it by using chrpath -d <binary> on Linux. Alternatively, use the -Wl,--disable-new-dtags flag during linking.

    Specify necessary paths only: Check if specific paths are needed, and then set RPATH only for them to avoid this warning.



ERROR: cannot find entry symbol _start

An error message like this

/system/usr/share/gcc/bin/../lib/gcc/aarch64-linux-android/10.2.0/../../../../aarch64-linux-android/bin/ld: warning: cannot find entry symbol _start; defaulting to 0000000000000e90

is printed when you compile a shared library with the linker option "-pie": When using this linker option, the linker searches for the symbol _start in the library but that symbol does not exist for a library.

To fix this error, remove the linker option "-pie". Alternative you can add the linker option "-nostartfiles".



ERROR: non-root user can not create hard links


Some Makefile configurations use hard links but in Android non-root user are not allowed to create hard links.

To fix this "error:" add the missing SELinux context for creating hardlinks by non-root user, execute as user root:

magiskpolicy --live "allow shell shell_data_file file link" 



ERROR: ld: error: unable to find library -lrt


On Android librt has been integrated into libc, and the -lrt option is unnecessary.



ERROR: ld: error: undefined reference due to --no-allow-shlib-undefined: wmempcpy


Solution:

Use a newer API version: wmempcpy is defined in libc.so for android-23 and newer, but not for earlier platforms:

[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/ModuleSrc/wget ] $ /data/develop/android/Scripts/check_android_glibc_symbol.sh  wmempcpy
Checking the symbol  ...
** ./aarch64-linux-android/21/libc.so:
** ./aarch64-linux-android/22/libc.so:
** ./aarch64-linux-android/23/libc.so:
000000000001a240 T wmempcpy
** ./aarch64-linux-android/24/libc.so:
000000000001b240 T wmempcpy
** ./aarch64-linux-android/26/libc.so:
000000000001c240 T wmempcpy
** ./aarch64-linux-android/27/libc.so:
000000000001c240 T wmempcpy
** ./aarch64-linux-android/28/libc.so:
000000000001e250 T wmempcpy
** ./aarch64-linux-android/29/libc.so:
000000000001e250 T wmempcpy
** ./aarch64-linux-android/30/libc.so:
000000000001f250 T wmempcpy
** ./aarch64-linux-android/31/libc.so:
0000000000020250 T wmempcpy
** ./aarch64-linux-android/32/libc.so:
0000000000020250 T wmempcpy
** ./aarch64-linux-android/33/libc.so:
0000000000020250 T wmempcpy
[ OmniRom 14 Dev - xtrnaw7@t15g /data/develop/android/ModuleSrc/wget ] $



Notes

/data/develop/android/Scripts/check_android_glibc_symbol.sh is a private script on my PC to check the libc libraries from all local NDKs for a symbol.
(see here for the command used for that)



ERROR: use of undeclared identifier 'nl_langinfo'


Solution:

The reason for errors like this

linux-low.cc:7015:22: error: use of undeclared identifier 'nl_langinfo'
 7015 |   const char *cset = nl_langinfo (CODESET)

is the missing support for nl_langinfo in Android

To fix the error use a hardcoded value in Android:

Replace the line

const char *cset = nl_langinfo (CODESET);

with

#ifdef __ANDROID__
// Android fallback for character set
const char *cset = "UTF-8";
#else
#include <langinfo.h>
const char *cset = nl_langinfo(CODESET);
#endif



ERROR: Pointer tag for 0xdbcd000000060106 was truncated


If you get an error like this:

clang++: error: unable to execute command: Aborted
clang++: error: linker command failed due to signal (use -v to see invocation)
usr/ndk/r27b/sysroot/usr/lib/aarch64-linux-android/35 /data/local/tmp/develop/sysroot/usr/lib/libgmp.a -lc -ldl -pthread                                                            <
Pointer tag for 0xdbcd000000060106 was truncated, see 'https://source.android.com/devices/tech/debug/tagged-pointers'.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
clang++: error: unable to execute command: Aborted
clang++: error: linker command failed due to signal (use -v to see invocation)
[clang19 toolchain] 1|ASUS_I006D:/data/local/tmp/develop/gdb-16.1/gdb $

repeat the make command and check the value after the Pointer tag for : If this value is different for each execution, there is most likely not enough free memory to link the executable.

This error may be disappear after a reboot of the phone.



ERROR: ld.lld: error: undefined symbol: __assert_fail


To fix the error

ld.lld: error: undefined symbol: __assert_fail
>>> referenced by libunwind.cpp
>>>               libunwind.cpp.o:

add the libc to the Linker and compiler Flags:

LDFLAGS="${LDFLAGS} -lc"
CXXFLAGS="${CXXFLAGS} -lc" 



ERROR: ld.lld: error: undefined reference: frexp


To fix the errors

ld.lld: error: undefined reference: frexp
>>> referenced by ../lib/.libs/libunistring.so (disallowed by --no-allow-shlib-undefined)

ld.lld: error: undefined reference: frexpl
>>> referenced by ../lib/.libs/libunistring.so (disallowed by --no-allow-shlib-undefined)

ld.lld: error: undefined reference: ldexpl
>>> referenced by ../lib/.libs/libunistring.so (disallowed by --no-allow-shlib-undefined)


add the libm to the linker and compiler flags

LDFLAGS="${LDFLAGS} -lm"
CXXFLAGS="${CXXFLAGS} -lm" 



How to define the value used by the marco  __BIONIC_AVAILABILITY_GUARD


The macro __BIONIC_AVAILABILITY_GUARD is part of the Android Bionic headers and is used to conditionally include APIs based on the API level. It evaluates to a boolean depending on whether the current value for the definition __ANDROID_API__ Is high enough.

E.g.

#if __BIONIC_AVAILABILITY_GUARD(23)
   // Only compiled if __ANDROID_API__ >= 23
#endif

The code in this if clause is only used if the value for __ANDROID_API__ is 23 or higher. To define the value for __ANDROID_API__, use the the compiler parameter

-D__ANDROID_API__=23

or, if using configure,

CFLAGS="${CFLAGS} -D__ANDROID_API__=23" ./configure


To check, if __ANDROID_API__ is already defined by default in the C compiler use this command:

$CC  -dM -E - < /dev/null | grep ANDROID


To print the current value of __ANDROID_API__ while compiling the source code, add this statement to the source file:

#define STR(x) #x
#define XSTR(x) STR(x)

#pragma message("__ANDROID_API__ = " XSTR(__ANDROID_API__))

Example output of the pragma message

openat-die.c:21:9: warning: __ANDROID_API__ = 31 [-W#pragma-messages]



ERROR: openat-die.c:37:3: error: use of undeclared identifier 'error'


In the source code for some programs (like for example nano) the files used to define common functions (like error) are only included if the variable GNULIB_LIBPOSIX is defined but the configure script doesnot define this variable

To fix this kind of error add the definitions

-DGNULIB_LIBPOSIX

to the CFLAGS manually.



ERROR: error: expected ')' in the statement __attribute__((__sentinel__(1)));


If you get an error regarding the usage of the macro __sentinel__ like this

In file included from bsd-getentropy.c:33:
/data/local/tmp/sysroot/usr/ndk/r27b/sysroot/usr/include/unistd.h:151:20: error: expected ')'
  151 |     __attribute__((__sentinel__(1)));
      |                    ^
1 error generated.

check if the source code supports the variable HAVE_ATTRIBUTE__SENTINEL__ :

grep -r HAVE_ATTRIBUTE__SENTINEL__ *

If this is the case add

-DHAVE_ATTRIBUTE__SENTINEL__=1

to the variable CFLAGS.

If the variable is not used in the source code, re-define the macro __sentinel__ in the CFLAGS variable:

export CFLAGS="$CFLAGS -D\"__sentinel__(x)\"="

Note:

The character ( and ) are special characters for the shell. Therefor it might be necessary to un-define this macro via #undef in the source files using the macro.



ERROR: libintl.h not found


e.g.

include/gettext.h:27:11: fatal error: 'libintl.h' file not found
   27 | # include <libintl.h>

The include file libintl.h is used for internationalization (i18n), i.e. to support multilingual output. This is not supported in Android.

To fix it, add the configure option --disable-nls if supported by the configure script.


Or check the source files to see whether the NO_LOCALE definition is supported. In this case, try this configuration:

export CPPFLAGS="${CPPFLAGS} -DNO_LOCALE".

If nothing helps, create a dummy libintl.h:

// stub-libintl.h
#ifndef _LIBINTL_H
#define _LIBINTL_H
#define gettext(Msgid) (Msgid)
#define dgettext(Domainname, Msgid) (Msgid)
#define dcgettext(Domainname, Msgid, Category) (Msgid)
#define bindtextdomain(Domainname, Dirname) (Domainname)
#define textdomain(Domainname) (Domainname)
#endif



ERROR: ld.lld: error: undefined symbol: bzero


bzero()
is outdated and not supported in Android libc. The function can be defined like this if requried:

void bzero(void *s, size_t n) {
    memset(s, 0, n);
}



ERROR: ./include/fileutils.h:90:19: error: static declaration of 'close_range' follows non-static declaration


Since API 34 close_range is an official system call in the Android NDK. If the configure script does not detect that, replace the code in the source file defining close_range with

/* in include/fileutils.h */
#if !defined(__ANDROID__) || __ANDROID_API__ < 34
static inline int close_range(unsigned int first, unsigned int last, int flags)
{
    errno = ENOSYS;
    return -1;
}
#endif



ERROR: ld.lld: error: duplicate symbol: memcmp


ld.lld: error: duplicate symbol: memcmp
>>> defined at memcmp.c
>>>            memcmp.o:(memcmp) in archive ./libdnet-stripped/src/.libs/libdnet.a
>>> defined at static_function_dispatch.S:37 (bionic/libc/arch-arm64/static_function_dispatch.S:37)
>>>            static_function_dispatch.o:(.text+0x10) in archive /data/develop/android/android-ndk/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc.a

To fix this error, either remove the definition for the duplicate function from one of the source files. Or add the compiler option

-Wl,--allow-multiple-definition

Please note that using this compiler option is only a hack, as you will not know which of the functions will be used by the linker.

 

back to top