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

Failing to cross-compile in Linux with Android NDK #2

Open
halfonsog opened this issue Jun 23, 2021 · 1 comment
Open

Failing to cross-compile in Linux with Android NDK #2

halfonsog opened this issue Jun 23, 2021 · 1 comment

Comments

@halfonsog
Copy link

halfonsog commented Jun 23, 2021

Hello,
The code compiles perfectly in Linux (Ubuntu 20.04.2 LTS 64), but it fails when trying to compile it for Android.
Your help is highly appreciated

I used this procedure:

$ git clone https://github.com/ufz/iphreeqc 
$ cd iphreeqc 
$ mkdir output 
$ export ANDROID_NDK=$ANDROID_SDK_ROOT/ndk/22.1.7171670 
$ PATH=$PATH:$ANDROID_NDK 
$ export TOOLCHAIN=$ANDROID_NDK/toolchains/llvm/prebuilt/linux-x86_64 
$ export TARGET=armv7a-linux-androideabi 
$ export API=21 
$ export AR=$TOOLCHAIN/bin/llvm-ar 
$ export CC=$TOOLCHAIN/bin/$TARGET$API-clang 
$ export AS=$CC 
$ export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++ 
$ export LD=$TOOLCHAIN/bin/ld 
$ export RANLIB=$TOOLCHAIN/bin/llvm-ranlib 
$ export STRIP=$TOOLCHAIN/bin/llvm-strip 
$ ./configure --prefix=$(pwd)/output --host $TARGET --disable-shared 
$ make   

When comparing configure results (linux vs android) these are the main differences:

    checking for GNU libc compatible malloc... yes
    checking for stdlib.h... (cached) yes
    checking for GNU libc compatible realloc... yes
    checking for working strtod... yes
    checking for pow... yes
    checking for GNU libc compatible malloc... no
    checking for stdlib.h... (cached) yes
    checking for GNU libc compatible realloc... no
    checking for working strtod... no
    checking for pow... no
    checking for pow in -lm... yes

make's output is hereafter:

Making all in src
make[1]: Entering directory '/home/hery/dev/iphreeqc-3.7.0-15749/output/src'
  CXX      CSelectedOutput.lo
  CXX      IPhreeqc.lo
  CXX      IPhreeqc_interface_F.lo
  CXX      IPhreeqcLib.lo
  CXX      phreeqcpp/cvdense.lo
  CXX      phreeqcpp/cvode.lo
../../src/phreeqcpp/cvdense.cpp:76:9: warning: 'malloc' macro redefined [-Wmacro-redefined]
#define malloc PHRQ_malloc
        ^
<command line>:31:9: note: previous definition is here
#define malloc rpl_malloc
        ^
  CXX      phreeqcpp/cxxKinetics.lo
1 warning generated.
../../src/phreeqcpp/cvode.cpp:77:9: warning: 'malloc' macro redefined [-Wmacro-redefined]
#define malloc MACHENV_MALLOC PHRQ_malloc
        ^
<command line>:31:9: note: previous definition is here
#define malloc rpl_malloc
        ^
1 warning generated.
  CXX      phreeqcpp/cxxMix.lo
  CXX      phreeqcpp/dense.lo
  CXX      phreeqcpp/Dictionary.lo
  CXX      phreeqcpp/dumper.lo
  CXX      phreeqcpp/Exchange.lo
  CXX      phreeqcpp/ExchComp.lo
  CXX      phreeqcpp/GasComp.lo
  CXX      phreeqcpp/gases.lo
  CXX      phreeqcpp/GasPhase.lo
  CXX      phreeqcpp/input.lo
  CXX      phreeqcpp/integrate.lo
  CXX      phreeqcpp/inverse.lo
../../src/phreeqcpp/inverse.cpp:5109:9: warning: result of comparison of constant -1 with expression of type 'char' is always true [-Wtautological-constant-out-of-range-compare]
                if (c != EOF && c != '\n' && i != MAX_LINE)
                    ~ ^  ~~~
../../src/phreeqcpp/inverse.cpp:5133:9: warning: result of comparison of constant -1 with expression of type 'char' is always false [-Wtautological-constant-out-of-range-compare]
                if (c == EOF)
                    ~ ^  ~~~
  CXX      phreeqcpp/ISolution.lo
  CXX      phreeqcpp/ISolutionComp.lo
  CXX      phreeqcpp/isotopes.lo
2 warnings generated.
  CXX      phreeqcpp/kinetics.lo
  CXX      phreeqcpp/KineticsComp.lo
  CXX      phreeqcpp/mainsubs.lo
  CXX      phreeqcpp/model.lo
  CXX      phreeqcpp/NameDouble.lo
../../src/phreeqcpp/model.cpp:3126:8: error: no member named 'isfinite' in namespace 'std'; did you mean 'finite'?
                if (!PHR_ISFINITE((double) delta[i]))
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../src/phreeqcpp/Phreeqc.h:1839:29: note: expanded from macro 'PHR_ISFINITE'
#    define PHR_ISFINITE(x) std::isfinite(x)
                            ^~~~~
/home/hery/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/math.h:373:5: note: 'finite' declared here
int finite(double __x) __attribute_const__;
    ^
../../src/phreeqcpp/model.cpp:3321:8: error: no member named 'isfinite' in namespace 'std'; did you mean 'finite'?
                if (!PHR_ISFINITE((double) delta[i]))
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../src/phreeqcpp/Phreeqc.h:1839:29: note: expanded from macro 'PHR_ISFINITE'
#    define PHR_ISFINITE(x) std::isfinite(x)
                            ^~~~~
/home/hery/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/math.h:373:5: note: 'finite' declared here
int finite(double __x) __attribute_const__;
    ^
../../src/phreeqcpp/model.cpp:4755:10: error: no member named 'isfinite' in namespace 'std'; did you mean 'finite'?
                                if (!PHR_ISFINITE((double) f))
                                     ^~~~~~~~~~~~~~~~~~~~~~~~
../../src/phreeqcpp/Phreeqc.h:1839:29: note: expanded from macro 'PHR_ISFINITE'
#    define PHR_ISFINITE(x) std::isfinite(x)
                            ^~~~~
/home/hery/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/math.h:373:5: note: 'finite' declared here
int finite(double __x) __attribute_const__;
    ^
../../src/phreeqcpp/model.cpp:4812:12: error: no member named 'isfinite' in namespace 'std'; did you mean 'finite'?
                                                        if (PHR_ISFINITE((double) d1) /*&& d1 < 5.0*/)
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~
../../src/phreeqcpp/Phreeqc.h:1839:29: note: expanded from macro 'PHR_ISFINITE'
#    define PHR_ISFINITE(x) std::isfinite(x)
                            ^~~~~
/home/hery/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/math.h:373:5: note: 'finite' declared here
int finite(double __x) __attribute_const__;
    ^
../../src/phreeqcpp/model.cpp:5479:10: error: no member named 'isfinite' in namespace 'std'; did you mean 'finite'?
                                if (!PHR_ISFINITE(my_array[(size_t)j * (count_unknowns + 1) + (size_t)i]))
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../src/phreeqcpp/Phreeqc.h:1839:29: note: expanded from macro 'PHR_ISFINITE'
#    define PHR_ISFINITE(x) std::isfinite(x)
                            ^~~~~
/home/hery/Android/Sdk/ndk/22.1.7171670/toolchains/llvm/prebuilt/linux-x86_64/bin/../sysroot/usr/include/math.h:373:5: note: 'finite' declared here
int finite(double __x) __attribute_const__;
    ^
5 errors generated.
make[1]: *** [Makefile:983: phreeqcpp/model.lo] Error 1
make[1]: *** Waiting for unfinished jobs....
make[1]: Leaving directory '/home/hery/dev/iphreeqc/output/src'
make: *** [Makefile:401: all-recursive] Error 1
@halfonsog
Copy link
Author

halfonsog commented Jun 24, 2021

I've managed to cross-compile the code with the following workarounds. But still the two first compiling warnings are shown in arm platforms (aarch64 and armv7a). For x86 (x86_64 and i686) no warnings were shown. I understand that affect the proper execution of the code. Still your help is needed.

  1. adding #include below #include <math.h>, in src/phreeqcpp/Phreeqc.h. Courtesy of Botje ([https://stackoverflow.com/questions/68100973/failing-to-cross-compile-c-library-with-android-ndk/68113060#68113060])
  2. overcome MALLOC/REALLOC errors with export ac_cv_func_malloc_0_nonnull=yes and export ac_cv_func_realloc_0_nonnull=yes
  3. adding -fPIC flag to the compiler

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

No branches or pull requests

1 participant