Discussion:
How to fix or at least get more details about the `incompatible target` issue?
(too old to reply)
Vitaliy Avramenko
2018-10-09 15:11:18 UTC
Permalink
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?
--
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 android-***@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/0a7231e3-1c55-4a5e-806b-abea11a611a6%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
AppCoder
2018-10-10 12:26:13 UTC
Permalink
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:

https://developer.android.com/ndk/guides/standalone_toolchain

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.
Post by Vitaliy Avramenko
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.
# 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
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?
--
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 android-***@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.
'Dan Albert' via android-ndk
2018-10-10 15:05:05 UTC
Permalink
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.
Post by AppCoder
It would be good to include the NDK version (as releases really change
what works and doesn't.)
--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....)
https://developer.android.com/ndk/guides/standalone_toolchain
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.
Post by Vitaliy Avramenko
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.
# 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
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?
--
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
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
<https://groups.google.com/d/msgid/android-ndk/f6f52e91-53fd-4eee-adba-970099e30b56%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 android-***@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/CAFVaGhuakrwe0X7jeHXRTeng2tQaEaDmHLETbqUV3ZV%2BPsrnxQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
John Dallman
2018-10-11 09:04:09 UTC
Permalink
Another vote for standalone toolchain. It's made my task, porting a huge C
library to Android, vastly easier.

John

On Wed, Oct 10, 2018 at 4:05 PM 'Dan Albert' via android-ndk <
Post by 'Dan Albert' via 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.
Post by AppCoder
It would be good to include the NDK version (as releases really change
what works and doesn't.)
--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....)
https://developer.android.com/ndk/guides/standalone_toolchain
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.
Post by Vitaliy Avramenko
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.
# 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
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?
--
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
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
<https://groups.google.com/d/msgid/android-ndk/f6f52e91-53fd-4eee-adba-970099e30b56%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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
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/CAFVaGhuakrwe0X7jeHXRTeng2tQaEaDmHLETbqUV3ZV%2BPsrnxQ%40mail.gmail.com
<https://groups.google.com/d/msgid/android-ndk/CAFVaGhuakrwe0X7jeHXRTeng2tQaEaDmHLETbqUV3ZV%2BPsrnxQ%40mail.gmail.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
--
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 android-***@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/CAH1xqgkTed-Mseqhm9w21%2BDcLKTgXzPArEcBTbaJpVOmqjw2%3DA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Vitaliy Avramenko
2018-10-11 12:55:57 UTC
Permalink
Thanks for everyone, friends. Standalone toolchain solved my issues. It
creates compiler that works with GNU build system and is compatible with
Android Studio.
--
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 android-***@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/5df730eb-f22e-4b0b-bb1d-d2dc9cb59b7b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Loading...