How to fix or at least get more details about the `incompatible target` issue?

1,194 views
Skip to first unread message

Vitaliy Avramenko

unread,
Oct 9, 2018, 4:58:30 PM10/9/18
to android-ndk
Hello, I have a lot of C/C++ code that I development for 10+ years, and now when I need to write Android application, I think it is logical to reuse this code instead of rewritting it in Java.
The code depends on common Linux libraries, including `curl`, `openssl`, `iconv`, etc.
I try to build these libraries for Android to compile my code.
I downloaded `ndk` and I tried to build at least `iconv`:

# Set Android NDK path
NDK_ROOT
=${HOME}/Android/Sdk/ndk-bundle
# Add Android NDK to system path
PATH
=${PATH}:${NDK_ROOT}/toolchains/llvm/prebuilt/linux-x86_64/bin
# Add compiler flags
CFLAGS
="--target=armv7-none-linux-androideabi21 --gcc-toolchain=/home/manager/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64 --sysroot=/home/manager/Android/Sdk/ndk-bundle/sysroot -I/business/platforms/android/armeabi-v7a/include -isystem /home/manager/Android/Sdk/ndk-bundle/sysroot/usr/include/arm-linux-androideabi -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb -Wa,--noexecstack -Wformat -Werror=format-security  -O2 -fPIC"
# Add libraries path
LDFLAGS
="-Wl,-rpath-link=${NDK_ROOT}/platforms/android-21/arch-arm/usr/lib -L${NDK_ROOT}/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/lib/gcc/arm-linux-androideabi/4.9.x"
# Generate tools pathes
CC
=clang
CXX
=clang++
AR
=llvm-ar
AS
=llvm-as
LD
=ld.lld
#RANLIB=${CROSS_COMPILE}-ranlib
NM
=llvm-nm
STRIP
=llvm-strip
LIBS
=
# Run configuration
./configure --prefix=${HOME}/Build --enable-static=yes --enable-shared=no --disable-rpath --enable-relocatable
I got these `clang` command line arguments from Android Studio logs.
`iconv` is compiled fine. However, when I try to link my C++ code with this library from Android Studio 3.2, I get following error always:

incompatible target
I thinks this error message is very far from own Google standards for error message. I says nothing except that it is impossible to compile. What specific parameters are incompatible? Is it CPU architecture, or `thumb` mode, or float ABI, etc? 
I see that there are a lot of such questions over Internet, and all of the have no answers.
May be someone in this group knows how to diagnose this error and fix it? 

AppCoder

unread,
Oct 10, 2018, 10:55:39 AM10/10/18
to android-ndk

It would be good to include the NDK version (as releases really change what works and doesn't.)

I think you have at least a disconnect between:

--target=armv7-none-linux-androideabi21
-march=armv7-a

armv7a and armv7 are different (incompatible) targets.  I suspect you want v7a everywhere, and
I agree that it's annoying that the clang/gcc/ndk options/paths for includes/libraries aren't exactly
the same.   (You may also be setting yourself up for more fun later on combining the gcc LDPATH
option and using clang....)

Look into the standalone tool chain:


It eats a bunch of disk space, but copies all the parts for an arch to a particular place.
This eliminates typos/guesses in the CFLAGS/LDFLAGS sections.

As an alternative, if you are building things that use CMake, the latest NDKs have ok support.
and you can just add

-DTARGET_ARCH=ANDROID \
-DANDROID_ABI=armeabi-v7a \
-DANDROID_PLATFORM=android-21 \
-DANDROID_STL=c++_shared \
-DCMAKE_TOOLCHAIN_FILE=${NDK_ROOT}/build/cmake/android.toolchain.cmake \

to your cmake command and it should pick all the right arch/target/include combos for you.

I haven't done iconv, but you can see the aws-cpp-sdk do openSSL/curl for older NDKs.
(They go the "build standalone tool chain" route but currently their NDK version detection
code is busted.)

       Dan S.

Dan Albert

unread,
Oct 10, 2018, 11:05:28 AM10/10/18
to android-ndk
Can you include the full error message? I have no idea what tool is giving you that error. I would guess that it's wrongly using your host's binutils, but I can't say for sure based on the information available.

Of course, you can probably just use https://developer.android.com/ndk/guides/standalone_toolchain and the problem will go away.

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/f6f52e91-53fd-4eee-adba-970099e30b56%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

John Dallman

unread,
Oct 11, 2018, 5:04:34 AM10/11/18
to andro...@googlegroups.com
Another vote for standalone toolchain. It's made my task, porting a huge C library to Android, vastly easier. 

John

Vitaliy Avramenko

unread,
Oct 11, 2018, 8:55:57 AM10/11/18
to android-ndk
Thanks for everyone, friends. Standalone toolchain solved my issues. It creates compiler that works with GNU build system and is compatible with Android Studio.
Reply all
Reply to author
Forward
0 new messages