compiling libcurl for android mips - android

i've created a script that compiles curl for android for 3 platforms, well more like 4:
1. armv5
2. armv7
3. x86
4. mips
i do it using this post in SO: enter link description here
for arm and x86 everything works ok (i use ndk toolchains and openssl specific library which i compiled for those same platform beforehand).
the only problematic platform is mips. i DO get the libcrul.a,la and .so BUT when trying to compile the executable curl the linkage fails:
libtool: link: mipsel-linux-android-gcc -O2 -Wno-system-headers -o .libs/curl curl-tool_binmode.o curl-tool_bname.o curl-tool_cb_dbg.o curl-tool_cb_hdr.o curl-tool_cb_prg.o curl-tool_cb_rea.o curl-tool_cb_see.o curl-tool_cb_wrt.o curl-tool_cfgable.o curl-tool_convert.o curl-tool_dirhie.o curl-tool_doswin.o curl-tool_easysrc.o curl-tool_formparse.o curl-tool_getparam.o curl-tool_getpass.o curl-tool_help.o curl-tool_helpers.o curl-tool_homedir.o curl-tool_hugehelp.o curl-tool_libinfo.o curl-tool_main.o curl-tool_metalink.o curl-tool_mfiles.o curl-tool_msgs.o curl-tool_operate.o curl-tool_operhlp.o curl-tool_panykey.o curl-tool_paramhlp.o curl-tool_parsecfg.o curl-tool_setopt.o curl-tool_sleep.o curl-tool_urlglob.o curl-tool_util.o curl-tool_vms.o curl-tool_writeenv.o curl-tool_writeout.o curl-tool_xattr.o ../lib/curl-strtoofft.o ../lib/curl-strdup.o ../lib/curl-rawstr.o ../lib/curl-nonblock.o ../lib/curl-warnless.o -L/usr/local/android-ndk/platforms/android-9/arch-mips/usr/lib -L/home/eyal/devel/openssl/lib ../lib/.libs/libcurl.so -lz
/usr/local/ndk-toolchains/mipsel-linux-android-4.6/bin/../lib/gcc/mipsel-linux-android/4.6/../../../../mipsel-linux-android/bin/ld: warning: libssl.so.1.1.0, needed by ../lib/.libs/libcurl.so, not found (try using -rpath or -rpath-link)
/usr/local/ndk-toolchains/mipsel-linux-android-4.6/bin/../lib/gcc/mipsel-linux-android/4.6/../../../../mipsel-linux-android/bin/ld: warning: libcrypto.so.1.1.0, needed by ../lib/.libs/libcurl.so, not found (try using -rpath or -rpath-link)
../lib/.libs/libcurl.so: undefined reference to `RAND_load_file'
../lib/.libs/libcurl.so: undefined reference to `SSL_CTX_use_certificate'
../lib/.libs/libcurl.so: undefined reference to `X509_load_crl_file'
../lib/.libs/libcurl.so: undefined reference to `SSL_set_fd'
../lib/.libs/libcurl.so: undefined reference to `SSL_set_connect_state'
../lib/.libs/libcurl.so: undefined reference to `SSL_CTX_free'
../lib/.libs/libcurl.so: undefined reference to `X509_free'
there are more 'undefined reference' errors, i spared u...
the library exists, the -L paths are ok, i checked, permission seems to be fine, and again, it works for both arm and x86 for android.
i'm using --host=mipsel-linux-android which might be wrong, but seems like it's the right one, the .so and .a are built so something went alright, but ld for some reason can't locate ssl and crypt once it's requested when trying to create and executable.
Anyone has any idea ? when tryying to use the toolchain manually to compile a file using libssl i was successful!
10x.

../lib/.libs/libcurl.so: undefined reference to `RAND_load_file'
These are OpenSSL functions. Do you have OpenSSL cross compiled for MIPS? If so, is it available?
libtool: link: mipsel-linux-android-gcc -O2 -Wno-system-headers -o .libs/curl curl-tool_binmode.o
curl-tool_bname.o curl-tool_cb_dbg.o curl-tool_cb_hdr.o curl-tool_cb_prg.o curl-tool_cb_rea.o
curl-tool_cb_see.o curl-tool_cb_wrt.o curl-tool_cfgable.o curl-tool_convert.o curl-tool_dirhie.o
curl-tool_doswin.o curl-tool_easysrc.o curl-tool_formparse.o curl-tool_getparam.o
curl-tool_getpass.o curl-tool_help.o curl-tool_helpers.o curl-tool_homedir.o curl-tool_hugehelp.o
curl-tool_libinfo.o curl-tool_main.o curl-tool_metalink.o curl-tool_mfiles.o curl-tool_msgs.o
curl-tool_operate.o curl-tool_operhlp.o curl-tool_panykey.o curl-tool_paramhlp.o
curl-tool_parsecfg.o curl-tool_setopt.o curl-tool_sleep.o curl-tool_urlglob.o curl-tool_util.o
curl-tool_vms.o curl-tool_writeenv.o curl-tool_writeout.o curl-tool_xattr.o ../lib/curl-strtoofft.o
../lib/curl-strdup.o ../lib/curl-rawstr.o ../lib/curl-nonblock.o ../lib/curl-warnless.o
-L/usr/local/android-ndk/platforms/android-9/arch-mips/usr/lib -L/home/eyal/devel/openssl/lib
../lib/.libs/libcurl.so -lz
OK... It looks like you specified the path to libcrypto and libssl:
-L/home/eyal/devel/openssl/lib
But it does not look like you passed in the actual libraries:
-lssl -lcrypto
I'm using --host=mipsel-linux-android which might be wrong...
This looks OK to me. Here's what the folks on the Autotools list told me to use for Android/ARM:
./configure --build=`./config.guess` --host=arm-linux-androideabi
I'd expect MIPS to use something like this because of what the Autotools folks passed on:
./configure --build=`./config.guess` --host=mipsel-linux-android
But I still think yours is OK.

Related

Building OpenSSL 1.0.2n for 64-bit Android with NDK r16b undefined reference to bsd_signal

I'm trying to get OpenSSL 1.0.2n to build using the latest Android NDK r16b. Building for 32-bit archs (armv7, x86) works just fine, but when I try building for 64-bit archs (arm64, x86_64) I get a linker error stating that bsd_signal is undefined:
shlib_target=; if [ -n "libcrypto.so.1.0.0 libssl.so.1.0.0" ]; then \
shlib_target="linux-shared"; \
elif [ -n "" ]; then \
FIPSLD_CC="aarch64-linux-android-gcc"; CC=/usr/local/ssl/fips-2.0/bin/fipsld; export CC FIPSLD_CC; \
fi; \
LIBRARIES="-L.. -lssl -L.. -lcrypto" ; \
/Applications/Xcode.app/Contents/Developer/usr/bin/make -f ../Makefile.shared -e \
APPNAME=openssl OBJECTS="openssl.o verify.o asn1pars.o req.o dgst.o dh.o dhparam.o enc.o passwd.o gendh.o errstr.o ca.o pkcs7.o crl2p7.o crl.o rsa.o rsautl.o dsa.o dsaparam.o ec.o ecparam.o x509.o genrsa.o gendsa.o genpkey.o s_server.o s_client.o speed.o s_time.o apps.o s_cb.o s_socket.o app_rand.o version.o sess_id.o ciphers.o nseq.o pkcs12.o pkcs8.o pkey.o pkeyparam.o pkeyutl.o spkac.o smime.o cms.o rand.o engine.o ocsp.o prime.o ts.o srp.o" \
LIBDEPS=" $LIBRARIES -ldl" \
link_app.${shlib_target}
req.o: In function `req_main':
req.c:(.text+0x368): undefined reference to `bsd_signal'
ca.o: In function `ca_main':
ca.c:(.text+0xe90): undefined reference to `bsd_signal'
ecparam.o: In function `ecparam_main':
ecparam.c:(.text+0x30): undefined reference to `bsd_signal'
s_server.o: In function `s_server_main':
s_server.c:(.text+0x32c0): undefined reference to `bsd_signal'
pkcs12.o: In function `pkcs12_main':
pkcs12.c:(.text+0x1134): undefined reference to `bsd_signal'
cms.o:cms.c:(.text+0x98): more undefined references to `bsd_signal' follow
collect2: error: ld returned 1 exit status
I saw that bsd_signal had been omitted from NDK at one point, but it was added back in NDK 13 (https://github.com/android-ndk/ndk/issues/160). Besides, if it were missing entirely I would expect the 32-bit builds to fail as well.
Here are the configurations I'm attempting to use for the arm64 build (this is actually done with a script, which is quite long. To avoid pasting the whole nonsense here, these are the values that wind up being used when it is executed):
export MACHINE=armv7
export ARCH=arm64
export CROSS_COMPILE="aarch64-linux-android-"
export ANDROID_SYSROOT="$ANDROID_NDK_ROOT/platforms/android-21/arch-arm64"
export SYSROOT="$ANDROID_SYSROOT"
export NDK_SYSROOT="$ANDROID_SYSROOT"
export ANDROID_NDK_SYSROOT="$ANDROID_SYSROOT"
export ANDROID_API=android-21
export ANDROID_DEV="$ANDROID_NDK_ROOT/platforms/android-21/arch-arm64/usr"
export HOSTCC=gcc
export ANDROID_TOOLCHAIN="$ANDROID_NDK_ROOT/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin"
export PATH="$ANDROID_TOOLCHAIN":"$PATH"
./Configure shared no-ssl2 no-ssl3 no-comp no-hw no-engine linux-generic64 --openssldir=/usr/local/ssl/android-21 -fPIE -D__ANDROID_API__=android-21 -I$ANDROID_NDK_ROOT/sysroot/usr/include -I$ANDROID_NDK_ROOT/sysroot/usr/include/aarch64-linux-android -B$ANDROID_NDK_ROOT/platforms/android-21/arch-arm64/usr/lib
make clean
make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER=" depend
make CALC_VERSIONS="SHLIB_COMPAT=; SHLIB_SOVER=" all
I've tried so many different things at this point I couldn't even begin to list them.
Anyone see what I'm missing here?
I would recommend to use the make that is shipped with Android NDK to build with NDK toolchain. If it's not on your PATH, you'll find it at
$ANDROID_NDK_ROOT/prebuilt/darwin-x86_64/bin/make
I don't think this is a real cause of your problem here.
bsd_signal is exported from platforms/android-21/arch-arm/usr/lib/libc.so, and also the corresponding libc.a, but not from platforms/android-21/arch-arm64/usr/lib/libc.so.
It is marked as __REMOVED_IN(21) in the unified headers, so I would expect the compiler to issue a warning about using an undefined function.
A possible workaround is to provide a dummy bsd_signal, as Felipe Cavalcanti proposed on GitHub.
The issue with bsd_signal seems to have been resolved in openssl 1.1 series.
You have a mistake on command line: use -D__ANDROID_API__=21 instead.
This definitely looks like a case of building against one API level and linking against another (or perhaps a mismatch of the header ABI vs the library ABI?). To rule out any configuration issues (and to simply your build even if it doesn't solve the issue), I'd recommend using a standalone toolchain.

no archive symbol table (run ranlib) while building libcryptopp.a through ndk-build

Here i am trying to build libcryptopp.a through ndk-build but i getting error as shown below.
Android.mk
Application.mk
setenv-android.sh its while creating libcryptopp.a and .so by using cryptopp 5.6.3
Error produced in terminal as below
$ /Users/kasbahapple/Documents/AndroidDocs/AndroidADT/adt-bundle-mac-x86_64-20140702/sdk/ndk-bundle/ndk-build
[armeabi] Gdbserver : [arm-linux-androideabi-4.8] libs/armeabi/gdbserver
[armeabi] Gdbsetup : libs/armeabi/gdb.setup
[armeabi-v7a] Gdbserver : [arm-linux-androideabi-4.8] libs/armeabi-v7a/gdbserver
[armeabi-v7a] Gdbsetup : libs/armeabi-v7a/gdb.setup
[x86] Gdbserver : [x86-4.8] libs/x86/gdbserver
[x86] Gdbsetup : libs/x86/gdb.setup
[armeabi] Executable : source_file
/Users/kasbahapple/Documents/AndroidDocs/AndroidADT/adt-bundle-mac-x86_64-20140702/sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: jni/nativelib/libcryptopp.a: no archive symbol table (run ranlib)
/Users/kasbahapple/Documents/AndroidDocs/AndroidADT/adt-bundle-mac-x86_64-20140702/sdk/ndk-bundle/platforms/android-8/arch-arm/usr/lib/crtbegin_dynamic.o:crtbrand.c:function _start: error: undefined reference to 'main'
collect2: error: ld returned 1 exit status
I really struggling to build c++ static library through NDK.
I looking for solution. Give me a complete steps if i doing wrong.
no archive symbol table (run ranlib) while building libcryptopp.a through ndk-build
After you build the Crypto++ library through Android.mk, you need to run ranlib on libcryptopp.a. Unfortunately, I don't know how to tell Android.mk to run ranlib.
I'm guessing - and its purely a guess - that you have to do this in two steps in Android.mk. You cannot cut to the chase and build the shared object directly from sources.
build libcryptopp.a, running ranlib
build libcryptopp.so from libcryptopp.a
setenv-android.sh its while creating libcryptopp.a and .so by using cryptopp 5.6.3
...
APP_STL = gnustl_static
The script setenv-android.sh uses STLport because of GNU licensing encumbrances. Your Android.mk uses GNU's STL.
You should probably also use the same C++ runtime libraries. Additionally, all libraries must use the same runtime. That means OpenGL, Crypto++, [Favorite library], must use the same C++ runtime, and there's no mixing and matching. In addition, because multiple libraries are using the C++ runtime, you must use the shared object, and not the static version.
There's a README in the NDK somewhere that discusses it. I think its called CPP-README or similar.
Also, when you invoke the setenv-android.sh, you must include a leading dot. Then you run the GNUmakefile-cross:
. ./setenv-android.sh
make -f GNUmakefile-cross static dynamic cryptest.exe
Finally, please don't post pictures. I can barely read them because my eyes are old. Usually, appeasing one user does not matter. In this case, I'm the guy who wrote the scripts and the wiki pages, so you want to make it easy on me, and not hard on me :)

Android r8b c++ shared library problems

This is a weird setup here. I compiled a custom NDK with GCC 4.7 (for Debian armhf chroot host). In testing, it compiles and runs regular c and c++ binaries on Android perfectly. When trying to compile a test shared library with C++ using:
arm-linux-androideabi-g++ -fPIC -shared test.cpp -lstdc++ -o test.so
I get numerous linker errors to _staticinitialization_destruction and _dso_handle being unreferenced.
I have both libstdc++.a and libstdc++.so available in the lib folder under arm-linux-androideabi directory. What is going on? There's hardly any info on Android C++ standalone compiling out there.
Edit
It seems __dso_handle is undefined for the iostream portion of the GNU STL. I found the answer from a 2005 Linux post. Still an issue in 2012 it seems :O lol.

Getting undefined reference error to stdout, stderr while compiling using x86 tool chain of Android NDK

I am trying to compile one of the native libraries libdigcert using Android NDK toolchain.
If I use arm toolchain everything works fine and if I link this library to my executable I dont get any linker errors.
If I use x86 toolchain, then I get linker errors which are showing undefined reference to stdout , stderr etc.
I used nm to read the difference between both .a files (arm and x86), and I see that, the x86 file has stdout undefined, while arm .a does not even mention stdout symbol.
Can anyone point me to what I am missing here?

cannot find -lgnustl_static: Compiling Android SDL port with NDK r7

I'm trying to build this port of libSDL for Android, using the new Android NDK r7 release:
https://github.com/pelya/commandergenius
I know I am doing some things to some degree "unsupported": I am using cygwin&windows despite that being mentioned in the README as no longer being supported. That being said, I can hack out shell scripts and solve my problems as necessary and have it compiling but not linking.
So anyways I have compiling working until the linking (sorry for large block, relevant part trimmed below):
/cygdrive/c/and/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-ar crs obj/local/armeabi/libflac.a ./obj/local/armeabi/objs-debug/flac/src/ogg_decoder_aspect.o ./obj/local/armeabi/objs-debug/flac/src/md5.o ./obj/local/armeabi/objs-debug/flac/src/stream_decoder.o ./obj/local/armeabi/objs-debug/flac/src/fixed.o ./obj/local/armeabi/objs-debug/flac/src/memory.o ./obj/local/armeabi/objs-debug/flac/src/stream_encoder.o ./obj/local/armeabi/objs-debug/flac/src/window.o ./obj/local/armeabi/objs-debug/flac/src/cpu.o ./obj/local/armeabi/objs-debug/flac/src/ogg_encoder_aspect.o ./obj/local/armeabi/objs-debug/flac/src/lpc.o ./obj/local/armeabi/objs-debug/flac/src/float.o ./obj/local/armeabi/objs-debug/flac/src/bitmath.o ./obj/local/armeabi/objs-debug/flac/src/metadata_object.o ./obj/local/armeabi/objs-debug/flac/src/ogg_helper.o ./obj/local/armeabi/objs-debug/flac/src/metadata_iterators.o ./obj/local/armeabi/objs-debug/flac/src/bitreader.o ./obj/local/armeabi/objs-debug/flac/src/bitwriter.o ./obj/local/armeabi/objs-debug/flac/src/stream_encoder_framing.o ./obj/local/armeabi/objs-debug/flac/src/crc.o ./obj/local/armeabi/objs-debug/flac/src/format.o ./obj/local/armeabi/objs-debug/flac/src/ogg_mapping.o
C:/and/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld.exe: cannot find -lgnustl_static
collect2: ld returned 1 exit status
/cygdrive/c/and/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/arm-linux-androideabi-ar crs obj/local/armeabi-v7a/libflac.a ./obj/local/armeabi-v7a/objs-debug/flac/src/ogg_decoder_aspect.o ./obj/local/armeabi-v7a/objs-debug/flac/src/md5.o ./obj/local/armeabi-v7a/objs-debug/flac/src/stream_decoder.o ./obj/local/armeabi-v7a/objs-debug/flac/src/fixed.o ./obj/local/armeabi-v7a/objs-debug/flac/src/memory.o ./obj/local/armeabi-v7a/objs-debug/flac/src/stream_encoder.o ./obj/local/armeabi-v7a/objs-debug/flac/src/window.o ./obj/local/armeabi-v7a/objs-debug/flac/src/cpu.o ./obj/local/armeabi-v7a/objs-debug/flac/src/ogg_encoder_aspect.o ./obj/local/armeabi-v7a/objs-debug/flac/src/lpc.o ./obj/local/armeabi-v7a/objs-debug/flac/src/float.o ./obj/local/armeabi-v7a/objs-debug/flac/src/bitmath.o ./obj/local/armeabi-v7a/objs-debug/flac/src/metadata_object.o ./obj/local/armeabi-v7a/objs-debug/flac/src/ogg_helper.o ./obj/local/armeabi-v7a/objs-debug/flac/src/metadata_iterators.o ./obj/local/armeabi-v7a/objs-debug/flac/src/bitreader.o ./obj/local/armeabi-v7a/objs-debug/flac/src/bitwriter.o ./obj/local/armeabi-v7a/objs-debug/flac/src/stream_encoder_framing.o ./obj/local/armeabi-v7a/objs-debug/flac/src/crc.o ./obj/local/armeabi-v7a/objs-debug/flac/src/format.o ./obj/local/armeabi-v7a/objs-debug/flac/src/ogg_mapping.o
C:/and/android-ndk-r7/toolchains/arm-linux-androideabi-4.4.3/prebuilt/windows/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld.exe: cannot find -lgnustl_static
collect2: ld returned 1 exit status
Relevant failure, if you can't parse that wall of text:
ld.exe: cannot find -lgnustl_static
Now, if I look at the Windows NDK release I find gnustl_* files here:
under ./android-ndk-r7/sources:
./cxx-stl/gnu-libstdc++/libs/armeabi/libgnustl_shared.so
./cxx-stl/gnu-libstdc++/libs/armeabi/libgnustl_static.a
./cxx-stl/gnu-libstdc++/libs/armeabi-v7a/libgnustl_shared.so
./cxx-stl/gnu-libstdc++/libs/armeabi-v7a/libgnustl_static.a
./cxx-stl/gnu-libstdc++/libs/x86/libgnustl_shared.so
./cxx-stl/gnu-libstdc++/libs/x86/libgnustl_static.a
I looked also at the linux android NDK distribution and they are packaged the same (only have libgnustl files, built, under the sources directory).
So I have 3 questions:
why would we be using -l to link libgnustl_static when it's a .a
file? Shouldn't that be just including the .a file in the object
list, or alternately be -lgnustl_shared?
why are these files only under "sources"? I would have expected them to be in the "toolchains" library NDK directory. How does anyone ever link against libgnustl?
Can I copy these files somewhere where they'll be seen by the linker? Just adding their directory with -L hasn't seemed to work, and plus I need to get the right versions linked with the right build target (armeabi vs armeabi-v7 vs x86)
This is a bug in gcc/NDK that manifests itself slightly different on Linux, Cygwin, and Windows (non Cygwin).
Here's what I did to fix it (works for Linux and for one of my developers who is blind and has to use Cygwin)...
Remove the line that says, APP_STL := gnustl_static from your Application.mk (it's broken in the NDK, and it's broken slightly differently on Linux Cygwin, Windows)
add a line to $(LOCAL_LDLIBS) in your Android.mk file that says:
$(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/libgnustl_static.a
also add two lines to Android.mk that say:
LOCAL_C_INCLUDES := $(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.6/include
LOCAL_C_INCLUDES += $(NDK_ROOT)/sources/cxx-stl/gnu-libstdc++/4.6/libs/armeabi-v7a/include
The foregoing will accomplish what having, APP_STL := gnustl_static in your Application.mk was supposed to.
In case this plagues anyone else, the solution is to remove -lgnustl_static and instead list
c:\path\to\armeabi\libs\libgnustl_static.a in the linker command.
Do not use /cygdrive style path, as the linker will fail to find the file. Use actual c:\...

Categories

Resources