Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLang support for android #637

Closed
strentler opened this issue Apr 12, 2018 · 10 comments
Closed

CLang support for android #637

strentler opened this issue Apr 12, 2018 · 10 comments

Comments

@strentler
Copy link

strentler commented Apr 12, 2018

Clang is now the default NDK compiler for Android. Support for GCC has stopped.

Looking at Android (Command Line), it looks like there is no support to compile Crypto++ for Android using Clang. setenv-android.sh should support compiling with Clang.

Also see Android NDK, Revision 16b (December 2017).

noloader added a commit that referenced this issue Apr 20, 2018
This makes room for a Clang/LLVM version of the script
Repository owner deleted a comment from strentler Apr 20, 2018
@noloader
Copy link
Collaborator

noloader commented Apr 20, 2018

@strentler,

I made a first pass using Clang. It is not working at the moment. The documentation pretty much sucks, and that's par for the course.

I would be interested in seeing the compiler options Eclipse uses when Clang is the compiler. Can you drop down into the command line, and use ndk-build to compile one of your projects? You may need ndk-build V=1 to get more verbose output. Then post the results here. Be sure it includes compiler and linker invocations.

I'm guessing we need to build out a new table of CXXFLAGS like we have at Android | GCC CXXFLAGS


The best I can tell, Clang is just plain broken:

$ /opt/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang -dumpmachine
/opt/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by /opt/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang)
/opt/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.15' not found (required by /opt/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang)
/opt/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/bin/clang: /lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.14' not found (required by /opt/android-ndk-r15c/toolchains/llvm/prebuilt/linux-x86_64/bin/../lib64/libc++.so)

@noloader
Copy link
Collaborator

noloader commented May 7, 2018

@strentler,

Were you able to generate a list of the compiler options needed for Clang? I've got a partial setenv-android-clang.sh, but Clang is dying on the GCC style options. I can't find documentation on the Clang options needed for a compile.

@KayEss
Copy link
Contributor

KayEss commented May 29, 2018

Android is now switching over to cmake, which I guess is both good and bad for this. I've made a stab at something for this. ARM builds seemed to work fine (there are some settings needed in the cmake configuration in gradle to go with it too). The latest NDK seems to have broken x86. Maybe it just needs the right compile option?

For crypto++ 7.0 I needed to patch pwdbased.h and add an include:

#include "algparam.h"

For x86_64 I get the following error though. I wonder if this is because an architecture flag is missing. The ones I'm setting so far are -maes -mpclmul -msha -msse4.1 -msse4.2 -mssse3. I'm afraid the GNU make stuff is totally impenetrable for me.

FAILED: /home/kirit/tmp/Android/Sdk/ndk-bundle/toolchains/llvm/prebuilt/linux-x86_64/bin/clang++  --target=i686-none-linux-android --gcc-toolchain=/home/kirit/tmp/Android/Sdk/ndk-bundle/toolchains/x86-4.9/prebuilt/linux-x86_64 --sysroot=/home/kirit/tmp/Android/Sdk/ndk-bundle/sysroot   -I../../../../src/main/cpp/fost-android-ndk/crypto/. -I/home/kirit/tmp/Android/Sdk/ndk-bundle/sources/android/cpufeatures -isystem /home/kirit/tmp/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++/include -isystem /home/kirit/tmp/Android/Sdk/ndk-bundle/sources/android/support/include -isystem /home/kirit/tmp/Android/Sdk/ndk-bundle/sources/cxx-stl/llvm-libc++abi/include -isystem /home/kirit/tmp/Android/Sdk/ndk-bundle/sysroot/usr/include/i686-linux-android -D__ANDROID_API__=14 -g -DANDROID -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -mstackrealign -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -std=c++14 -DBOOST_VERSION_MAJOR=65 -O0 -fno-limit-debug-info    -fPIC -maes -mpclmul -msha -msse4.1 -msse4.2 -mssse3 -MD -MT src/main/cpp/fost-android-ndk/crypto/CMakeFiles/crypto++.dir/crypto++/sha.cpp.o -MF src/main/cpp/fost-android-ndk/crypto/CMakeFiles/crypto++.dir/crypto++/sha.cpp.o.d -o src/main/cpp/fost-android-ndk/crypto/CMakeFiles/crypto++.dir/crypto++/sha.cpp.o -c /home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/sha.cpp
/home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/sha.cpp:1005:5: error: invalid operand for instruction
    ASJ(    jnz,     0, b)
    ^
/home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/cpu.h:623:23: note: expanded from macro 'ASJ'
        #define ASJ(x, y, z) GNU_ASJ(x, y, z)
                            ^
/home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/cpu.h:617:27: note: expanded from macro 'GNU_ASJ'
        #define GNU_ASJ(x, y, z) #x " " #y #z ";" NEW_LINE
                                ^
<scratch space>:207:2: note: expanded from here
"jnz"
^
<inline asm>:80:1: note: instantiated into assembly here
jnz 0b;
^
/home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/sha.cpp:1008:5: error: invalid operand for instruction
    ASJ(    jne,     0, b)
    ^
/home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/cpu.h:623:23: note: expanded from macro 'ASJ'
        #define ASJ(x, y, z) GNU_ASJ(x, y, z)
                            ^
/home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/cpu.h:617:27: note: expanded from macro 'GNU_ASJ'
        #define GNU_ASJ(x, y, z) #x " " #y #z ";" NEW_LINE
                                ^
<scratch space>:214:2: note: expanded from here
"jne"
^
<inline asm>:83:1: note: instantiated into assembly here
jne 0b;
^
/home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/sha.cpp:1039:5: error: invalid operand for instruction
    ASJ(    jnz,     1, b)
    ^
/home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/cpu.h:623:23: note: expanded from macro 'ASJ'
        #define ASJ(x, y, z) GNU_ASJ(x, y, z)
                            ^
/home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/cpu.h:617:27: note: expanded from macro 'GNU_ASJ'
        #define GNU_ASJ(x, y, z) #x " " #y #z ";" NEW_LINE
                                ^
<scratch space>:306:2: note: expanded from here
"jnz"
^
<inline asm>:128:1: note: instantiated into assembly here
jnz 1b;
^
/home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/sha.cpp:1050:5: error: invalid operand for instruction
    ASJ(    jne,     1, b)
    ^
/home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/cpu.h:623:23: note: expanded from macro 'ASJ'
        #define ASJ(x, y, z) GNU_ASJ(x, y, z)
                            ^
/home/kirit/Projects/bundler-dev/android-bundle-viewer/app/src/main/cpp/fost-android-ndk/crypto/crypto++/cpu.h:617:27: note: expanded from macro 'GNU_ASJ'
        #define GNU_ASJ(x, y, z) #x " " #y #z ";" NEW_LINE
                                ^
<scratch space>:5:2: note: expanded from here
"jne"
^
<inline asm>:134:1: note: instantiated into assembly here
jne 1b;
^
4 errors generated.

@KayEss
Copy link
Contributor

KayEss commented May 29, 2018

Just in case it's of use to anybody, this is the android build file that we were using with ndk-build. That was for crypto 5.6.2.

https://github.com/KayEss/fost-android-ndk/blob/a17746cfc5bc517229083d370f59b77ef13a2567/crypto%2B%2B.mk

@noloader
Copy link
Collaborator

noloader commented Jun 2, 2018

@KayEss, @strentler,

I was able to use ndk-build to build hello-jni with the latest NDK to get the updated CXXFLAGS. They were added to Android (Command Line) | Clang CXXFLAGS on the wiki.

I made some modifications to our current script but things are failing pretty bad. I'll keep chiseling away at the problems.

@Skycoder42
Copy link
Contributor

What is the current status for this? I can't seem to find a setenv-android-clang.sh in the repository or n the wiki?

Also, with NDK v18, gcc has completely been removed and was replaced with a bash script that simply invokes clang, which means it is currently impossible to compile cryptopp for android with the recent NDK

@Skycoder42
Copy link
Contributor

I also can extract compiler flags from Qt as well, if you need more examples, as Qt managed to completly port to clang.

@KayEss
Copy link
Contributor

KayEss commented Dec 9, 2018

We have a cmake config that works for Android, Linux and Mac OS: https://github.com/KayEss/fost-crypto/blob/master/CMakeLists.txt

@Skycoder42
Copy link
Contributor

@KayEss Thank you! I was able to create an qmake pro file based on your example that compiles successfully on all platforms I care for (including the arm64_v8a, armv7 and x86 android architectures). (See https://github.com/Skycoder42/QtDataSync/blob/master/src/3rdparty/cryptopp/cryptopp.pro).

@noloader
Copy link
Collaborator

noloader commented Feb 9, 2019

@strentler,

I'm going to close this report because we are working Issue 763, Building for Android using NDK not supported on Windows hosts. The 763 issue has an improved script that should close the gaps for compilers like Clang and GCC, and platforms like Linux and Windows.

@noloader noloader closed this as completed Feb 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants