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

android: use CC to compile cpu-features #733

Merged
merged 1 commit into from
Nov 16, 2018

Conversation

OneBlue
Copy link
Contributor

@OneBlue OneBlue commented Nov 4, 2018

Hello,

I recently had to build cryptopp on android, and I encountered some build issues.

This PR contains changes that correct some of those issues.

Note: Tested using android-ndk-r18b-linux-x86_64 on Linux. Built for arm64.

Detail

Compiling C as C++

The android NDK has migrated from gcc to clang.

One of the first issue I had came from:

	$(CXX) $(strip $(CXXFLAGS) -fpermissive -c) cpu-features.c

Because clang would try to compile cpu-features.c as C++, which of course yields a lot of errors.

Changing to $(CC) fixed the problem.

Missing cpu-feature

Once compiled and installed, my android application would fail to load the library with the following error message:

2018-10-30 21:04:31.371 15477-15477/[redacted] E/AndroidRuntime: FATAL EXCEPTION: main
    Process: [redacted], PID: 15477
    java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "android_getCpuFeatures" referenced by "[redacted]/lib/arm64/libcryptopp.so"...
        at java.lang.Runtime.loadLibrary0(Runtime.java:1016)
        at java.lang.System.loadLibrary(System.java:1657)
        at [redacted].MainActivity.<clinit>(MainActivity.java:13)

That's because the object $(AOSP_CPU_OBJ) is omitted from the rule libcryptopp.so.

Adding the object fixed that problem.

@noloader
Copy link
Collaborator

@OneBlue,

Sorry for the delay here.

Because clang would try to compile cpu-features.c as C++, which of course yields a lot of errors.

Could you provide the errors, please.

Also note we have an open bug report at Android Issue 65641866, Dirty compile when compiling cpu-feature.c with C++ compiler

Once compiled and installed, my android application would fail to load the library with the following error message:

Yeah, that's a problem.

I'm going to merge your PR and then back-out the compiler change. I think AOSP is working on the dirty compile.

@noloader noloader merged commit 2d2f69c into weidai11:master Nov 16, 2018
noloader added a commit that referenced this pull request Nov 16, 2018
@noloader
Copy link
Collaborator

noloader commented Nov 16, 2018

Thanks @OneBlue.

The PR was merged and we switched back to a C++ compiler at Commit 0ac7b252213c. My worry is CXXFLAGS will contain something that chokes a C compiler.

AOSP is responsible for cleaning up the dirty compile. It looks like they are working on the issue so it should be cleared soon.

Thanks again for the help.

Ping @abdes. Can you verify the CMake project includes the symbol for Android's shared object.

@abdes
Copy link

abdes commented Nov 16, 2018

Ping @abdes. Can you verify the CMake project includes the symbol for Android's shared object.

The current state of the make build does not seem to have Android support. As I'm not familiar with android NDK, I suggest we create an issue in cryptopp-cmake to add support for android NDK and maybe ask for help from the community members that use it on Android with cmake.

@OneBlue
Copy link
Contributor Author

OneBlue commented Nov 17, 2018

Thanks a lot for merging !

@abdes:

Because clang would try to compile cpu-features.c as C++, which of course yields a lot of errors.

Could you provide the errors, please.

Below are the errors I got when I compiled:

$ source ./setenv-android.sh arm64-v8a llvm-static && make -f GNUmakefile-cross shared
[...]
aarch64-linux-android-g++ -DNDEBUG -g2 -O3 -fPIC -pipe -Wall -D__ANDROID_API__=21 -funwind-tables -fexceptions -frtti -DANDROID --sysroot=/tmp/bpm/android-ndk-r18b/sysroot -Wa,--noexecstack -I/tmp/bpm/android-ndk-r18b/sources/cxx-stl/llvm-libc++/include -I/tmp/bpm/android-ndk-r18b/sysroot/usr/include/aarch64-linux-android -fpermissive -c cpu-features.c
clang++: warning: treating 'c' input as 'c++' when in C++ mode, this behavior is deprecated [-Wdeprecated]
cpu-features.c:399:13: error: assigning to 'const char *' from incompatible type 'const void *'
        q = memchr(p, ',', end-p);
            ^~~~~~~~~~~~~~~~~~~~~
cpu-features.c:693:15: error: assigning to 'char *' from incompatible type 'void *'
    cpuinfo = malloc(cpuinfo_len);
              ^~~~~~~~~~~~~~~~~~~
2 errors generated.
GNUmakefile-cross:569: recipe for target 'cpu-features.o' failed
make: *** [cpu-features.o] Error 1

@noloader
Copy link
Collaborator

Below are the errors I got when I compiled

Yeah, that's a problem. In the past I observed them as warnings. They need to be fixed now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants