Vitaliy Avramenko
2018-10-09 15:11:18 UTC
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?
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.
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.