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

Cross-compiling for android does not work anymore on OpenSUSE and Travis CI #59

Closed
eriknellessen opened this issue Nov 5, 2015 · 5 comments

Comments

@eriknellessen
Copy link

Cross-compiling produced many errors today on OpenSUSE 13.1 and Travis CI (Ubuntu 12.40).

We used to follow the procedure described in http://www.cryptopp.com/wiki/Android_%28Command_Line%29 . That means, we downloaded the patched files and then built cryptopp for android. This still worked 7 days ago. With the new commits today, this does not work anymore.

I believe that this is because of the many changes in the new commits. We tried to apply the patch (from the wiki) to a fresh copy of cryptopp, but patch failed:

> patch < mobile.diff
patching file wait.h
Hunk #1 succeeded at 19 with fuzz 1 (offset 4 lines).
patching file wait.cpp
Reversed (or previously applied) patch detected!  Assume -R? [n] 
Apply anyway? [n] y
Hunk #1 FAILED at 363.
1 out of 1 hunk FAILED -- saving rejects to file wait.cpp.rej
patching file validat1.cpp
Hunk #1 succeeded at 18 (offset 6 lines).
patching file test.cpp
Hunk #1 succeeded at 34 (offset 5 lines).
patching file iterhash.h
patching file GNUmakefile
Hunk #1 FAILED at 1.
Hunk #2 FAILED at 36.
Hunk #3 FAILED at 86.
Hunk #4 FAILED at 146.
Hunk #5 FAILED at 165.
5 out of 5 hunks FAILED -- saving rejects to file GNUmakefile.rej
patching file config.h
Hunk #1 succeeded at 93 with fuzz 2 (offset 47 lines).
Hunk #2 succeeded at 355 with fuzz 1 (offset 101 lines).
Hunk #3 FAILED at 367.
Hunk #4 succeeded at 513 (offset 128 lines).
1 out of 4 hunks FAILED -- saving rejects to file config.h.rej
patching file algparam.h
Hunk #1 FAILED at 320.
1 out of 1 hunk FAILED -- saving rejects to file algparam.h.rej

We then had a look at the new GNUmakefile and saw, that it already has built-in many features of the patch. So we tried to just use that GNUmakefile for cross-compiling for android. That did not work with the following error message:

arm-linux-androideabi-g++ -DNDEBUG -g2 -O2 -fPIC -march=native -pipe -c cryptlib.cpp
Assembler messages:
Error: unknown architecture `native'

Error: unrecognized option -march=native
cc1plus: error: unrecognized argument in option '-march=native'
cc1plus: note: valid arguments to '-march=' are: armv2 armv2a armv3 armv3m armv4 armv4t armv5 armv5e armv5t armv5te armv6 armv6-m armv6j armv6k armv6s-m armv6t2 armv6z armv6zk armv7 armv7-a armv7-m armv7-r armv7e-m armv8-a iwmmxt iwmmxt2 native

So we changed the GNUmakefile and just commented out the line CXXFLAGS += -march=native (dirty). Cryptopp then compiled, but when we built our library depending on cryptopp, we encountered the following error:

include/cryptopp/config.h:667:3: error: #error "std::uncaught_exception is not available. This is likely a configuration error."
 # error "std::uncaught_exception is not available. This is likely a configuration error."
   ^
include/cryptopp/secblock.h: In member function 'void CryptoPP::AllocatorBase<T>::construct(U*, Args&& ...)':
include/cryptopp/secblock.h:64:66: error: 'forward' is not a member of 'std'
     void construct(U* ptr, Args&&... args) {::new ((void*)ptr) U(std::forward<Args>(args)...);}
                                                                  ^
include/cryptopp/secblock.h:64:83: error: expected primary-expression before '>' token
     void construct(U* ptr, Args&&... args) {::new ((void*)ptr) U(std::forward<Args>(args)...);}
                                                                                   ^

Did you already test cross-compiling for android? Can you reproduce the problems?

@noloader
Copy link
Collaborator

noloader commented Nov 5, 2015

Did you already test cross-compiling for android?

Yes. In fact, I had finished an Android and an iOS cross-compile about 2 hours before you posted (It was literally 2 or hours or so).

That means, we downloaded the patched files and then built cryptopp for android. This still worked 7 days ago. With the new commits today, this does not work anymore.

Ah, OK. All the cross-compile stuff has been added to the library. There's no need to apply the patch. All you need are:

You can find setenv-android.sh and GNUmakefile-cross at https://cryptopp.com/wiki/Android_%28Command_Line%29#Downloads. I just updated the Download section, so the text has changed based on the feedback from this report.

Here is the 10 second tour:

# Check-out from GitHub
git clone https://github.com/weidai11/cryptopp.git cryptopp
cd cryptopp

# Unpack....
curl https://cryptopp.com/w/images/0/0a/Setenv-android.sh.zip -o setenv-android.sh.zip
unzip -aoq setenv-android.sh.zip -d ./
curl https://cryptopp.com/w/images/b/b1/GNUmakefile-cross.zip -o GNUmakefile-cross.zip
unzip -aoq GNUmakefile-cross.zip -d ./

# Tweak setenv-android.sh to suit your taste. Next, the good stuff...

# Note the leading dot on the the command below
.  ./setenv-android.sh
make -f GNUmakefile-cross

Or:

make -f GNUmakefile-cross static dynamic cryptest.exe

And here is what it looks like:

$ . ./setenv-android.sh 
ANDROID_NDK_ROOT: /opt/android-ndk-r10e
ANDROID_EABI: arm-linux-androideabi-4.9
ANDROID_ARCH: arch-arm
ANDROID_ARMV7A: 1
ANDROID_API: android-21
ANDROID_SYSROOT: /opt/android-ndk-r10e/platforms/android-21/arch-arm
ANDROID_TOOLCHAIN: /opt/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin
ANDROID_FLAGS: -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb
ANDROID_STL_INC: /opt/android-ndk-r10e/sources/cxx-stl/stlport/stlport/
ANDROID_STL_LIB: /opt/android-ndk-r10e/sources/cxx-stl/stlport/libs/armeabi-    v7a/libstlport_shared.so
$ make -f GNUmakefile-cross 
arm-linux-androideabi-g++ -DNDEBUG -g3 -O2 -Wall -DCRYPTOPP_DISABLE_ASM -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb --sysroot=/opt/android-ndk-r10e/platforms/android-21/arch-arm -I/opt/android-ndk-r10e/sources/cxx-stl/stlport/stlport/ -MM *.cpp > GNUmakefile.deps
arm-linux-androideabi-g++ -DNDEBUG -g3 -O2 -Wall -DCRYPTOPP_DISABLE_ASM -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb --sysroot=/opt/android-ndk-r10e/platforms/android-21/arch-arm -I/opt/android-ndk-r10e/sources/cxx-stl/stlport/stlport/ -c cryptlib.cpp
arm-linux-androideabi-g++ -DNDEBUG -g3 -O2 -Wall -DCRYPTOPP_DISABLE_ASM -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb --sysroot=/opt/android-ndk-r10e/platforms/android-21/arch-arm -I/opt/android-ndk-r10e/sources/cxx-stl/stlport/stlport/ -c cpu.cpp
...

Can you reproduce the problems?

No, but I believe they exist.

The root cause is our documentation is stale. I think we should leave this open until we update the docs.


include/cryptopp/config.h:667:3: error: #error "std::uncaught_exception is not available. This is likely a configuration error."

I believe this is because the setup is bent. I did not experience it when using the arm-linux-androideabi-g++ compiler.

@noloader
Copy link
Collaborator

noloader commented Nov 5, 2015

@eriknellessen,

Cross-compiling for android does not work anymore on OpenSUSE and Travis CI ...

By the way, I'm happy to work directly with package maintainers. I view this as a partnership between us. If the maintainer has any questions, then ask them to reach out to me directly.

If OpenSUSE needs an accommodation, then they need to reach out to us quickly. We want to release 5.6.3 soon. We effectively performed the pre-release check-in yesterday. Once we release, we won't be able to get changes into 5.6.3 for them (if they want or need something).

@eriknellessen
Copy link
Author

Thank you for your help.

I used the GNUmakefile-cross, which is already in the repository. The compiling then worked.

The third error, i.e.

include/cryptopp/config.h:667:3: error: #error "std::uncaught_exception is not available. This is likely a configuration error."
 # error "std::uncaught_exception is not available. This is likely a configuration error."
   ^
include/cryptopp/secblock.h: In member function 'void CryptoPP::AllocatorBase<T>::construct(U*, Args&& ...)':
include/cryptopp/secblock.h:64:66: error: 'forward' is not a member of 'std'
     void construct(U* ptr, Args&&... args) {::new ((void*)ptr) U(std::forward<Args>(args)...);}
                                                                  ^
include/cryptopp/secblock.h:64:83: error: expected primary-expression before '>' token
     void construct(U* ptr, Args&&... args) {::new ((void*)ptr) U(std::forward<Args>(args)...);}
                                                                                   ^

still is present. But this is, when we build our library. So this has only indirectly to do with cryptopp. I will have a look at this next week and inform you about the progress.

To prevent misunderstandings: I am not a package maintainer. The OS names in the title of this issue were just there to inform you about the platforms we are building cryptopp on.

@noloader
Copy link
Collaborator

noloader commented Nov 9, 2015

But this is, when we build our library. So this has only indirectly to do with cryptopp...

OK, thanks. I'm going to close this report to keep things tidy.

For completeness, we cannot duplicate it (see below).

$ . ./setenv-android.sh 
ANDROID_NDK_ROOT: /opt/android-ndk-r10e
ANDROID_EABI: arm-linux-androideabi-4.9
ANDROID_ARCH: arch-arm
ANDROID_ARMV7A: 1
ANDROID_API: android-21
ANDROID_SYSROOT: /opt/android-ndk-r10e/platforms/android-21/arch-arm
ANDROID_TOOLCHAIN: /opt/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin
ANDROID_FLAGS: -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb
ANDROID_STL_INC: /opt/android-ndk-r10e/sources/cxx-stl/stlport/stlport/
ANDROID_STL_LIB: /opt/android-ndk-r10e/sources/cxx-stl/stlport/libs/armeabi-v7a/libstlport_shared.so

$ make -f GNUmakefile-cross static dynamic cryptest.exe
...

arm-linux-androideabi-g++ -DNDEBUG -g3 -O2 -Wall -DCRYPTOPP_DISABLE_ASM -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb
  --sysroot=/opt/android-ndk-r10e/platforms/android-21/arch-arm -I/opt/android-ndk-r10e/sources/cxx-stl/stlport/stlport/ -c cryptlib.cpp
arm-linux-androideabi-g++ -DNDEBUG -g3 -O2 -Wall -DCRYPTOPP_DISABLE_ASM -mfloat-abi=softfp -mfpu=vfpv3-d16 -mthumb
  --sysroot=/opt/android-ndk-r10e/platforms/android-21/arch-arm -I/opt/android-ndk-r10e/sources/cxx-stl/stlport/stlport/ -c cpu.cpp

...


  include/cryptopp/secblock.h:64:83: error: expected primary-expression before '>' token
      void construct(U* ptr, Args&&... args) {::new ((void*)ptr) U(std::forward<Args>(args)...);}

My guess is a compiler is pretending to be C++11 (or it is and it does not have the feature yet). We have to jump through some hoops on Apple platforms because Apple supplies compilers that pretend to be C++11. See the comments in config.h around line 590

If its still a problem for you, then please (1) open another bug report for the SecBlock issue, (2) tell us about the toolchain you are using, and (3) tell us how to duplicate it.

@noloader noloader closed this as completed Nov 9, 2015
@noloader
Copy link
Collaborator

@eriknellessen - we performed a complete overhaul of the Android docs. Please let me know what you think, or if you ave any troubles.

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

2 participants