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

Compilation fails with android ndk r15b #3826

Closed
deveee opened this issue Jul 2, 2017 · 13 comments
Closed

Compilation fails with android ndk r15b #3826

deveee opened this issue Jul 2, 2017 · 13 comments

Comments

@deveee
Copy link

deveee commented Jul 2, 2017

Here is the error:

...
./libcrypto.so: error: undefined reference to 'stderr'
./libcrypto.so: error: undefined reference to 'stdin'
./libcrypto.so: error: undefined reference to 'signal'
./libcrypto.so: error: undefined reference to 'tcsetattr'
./libcrypto.so: error: undefined reference to 'tcgetattr'
collect2: error: ld returned 1 exit status
make[2]: *** [link_app.gnu] Error 1
make[2]: Leaving directory `/home/Dokumenty/programowanie/supertuxkart/supertuxkart-git/android/obj/openssl'
make[1]: *** [fuzz/asn1-test] Error 2
make[1]: *** Waiting for unfinished jobs....
./libcrypto.so: error: undefined reference to 'stderr'
./libcrypto.so: error: undefined reference to 'stdin'
./libcrypto.so: error: undefined reference to 'signal'
./libcrypto.so: error: undefined reference to 'tcsetattr'
./libcrypto.so: error: undefined reference to 'tcgetattr'
collect2: error: ld returned 1 exit status
make[2]: *** [link_app.gnu] Error 1
make[2]: Leaving directory `/home/Dokumenty/programowanie/supertuxkart/supertuxkart-git/android/obj/openssl'
make[1]: *** [fuzz/asn1parse-test] Error 2
./libcrypto.so: error: undefined reference to 'stderr'
./libcrypto.so: error: undefined reference to 'stdin'
./libcrypto.so: error: undefined reference to 'signal'
./libcrypto.so: error: undefined reference to 'tcsetattr'
./libcrypto.so: error: undefined reference to 'tcgetattr'
fuzz/bndiv.o:bndiv.c:function FuzzerTestOneInput: error: undefined reference to 'stdout'
collect2: error: ld returned 1 exit status
make[2]: *** [link_app.gnu] Error 1
make[2]: Leaving directory `/home/Dokumenty/programowanie/supertuxkart/supertuxkart-git/android/obj/openssl'
./libcrypto.so: error: undefined reference to 'stderr'
./libcrypto.so: error: make[1]: undefined reference to*** [fuzz/bndiv-test] Error 2 
'stdin'
./libcrypto.so: error: undefined reference to 'signal'
./libcrypto.so: error: undefined reference to 'tcsetattr'
./libcrypto.so: error: undefined reference to 'tcgetattr'
fuzz/bignum.o:bignum.c:function FuzzerTestOneInput: error: undefined reference to 'stdout'
collect2: error: ld returned 1 exit status
make[2]: *** [link_app.gnu] Error 1
make[2]: Leaving directory `/home/Dokumenty/programowanie/supertuxkart/supertuxkart-git/android/obj/openssl'
make[1]: *** [fuzz/bignum-test] Error 2
LD_LIBRARY_PATH=.: arm-linux-androideabi-gcc -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSLDIR="/usr/local/ssl" -DENGINESDIR="/usr/local/lib/engines-1.1" -Wall -O3 -pthread -mandroid -fPIC --sysroot=/home/Dokumenty/programowanie/supertuxkart/supertuxkart-git/android/obj/sysroot -Wa,--noexecstack -fPIC -DOPENSSL_USE_NODELETE -Wl,-znodelete -shared -Wl,-Bsymbolic -Wl,-soname=libssl.so.1.1 -o ./libssl.so.1.1 -Wl,--whole-archive,--version-script=ssl.map ./libssl.a -Wl,--no-whole-archive -L. -lcrypto -ldl
make[2]: Leaving directory `/home/Dokumenty/programowanie/supertuxkart/supertuxkart-git/android/obj/openssl'
make[1]: Leaving directory `/home/Dokumenty/programowanie/supertuxkart/supertuxkart-git/android/obj/openssl'
make: *** [all] Error 2
Error ocurred.

I can send full log if you need it.

It was working fine with ndk r12b and r13b that I was using before.

Openssl has been configured with

./Configure android --cross-compile-prefix="$HOST-"

where HOST=arm-linux-androideabi

Here is the build script that I'm using:
https://github.com/supertuxkart/stk-code/blob/master/android/make.sh

I tested current stable version 1.1.0f and tbh. I checked only armv7 compilation. I will look how x86 compilation works later.

@levitte
Copy link
Member

levitte commented Jul 2, 2017

I suspect that adding "no-stdio" to your configuration should fix things.

@deveee
Copy link
Author

deveee commented Jul 3, 2017

Indeed the "no-stdio" helped with older openssl version. But the 1.1.0f still complains in different place:

make[2]: Entering directory `/home/Dokumenty/programowanie/supertuxkart/supertuxkart-git/android/obj/openssl'
LD_LIBRARY_PATH=.: arm-linux-androideabi-gcc -DDSO_DLFCN -DHAVE_DLFCN_H -DNDEBUG -DOPENSSL_THREADS -DOPENSSL_NO_STATIC_ENGINE -DOPENSSL_PIC -DOPENSSLDIR="/usr/local/ssl" -DENGINESDIR="/usr/local/lib/engines-1.1" -Wall -O3 -pthread -mandroid -fPIC --sysroot=/home/Dokumenty/programowanie/supertuxkart/supertuxkart-git/android/obj/sysroot -Wa,--noexecstack -pie -o test/buildtest_aes test/buildtest_aes.o -L. -lssl -L. -lcrypto -ldl
./libcrypto.so: error: undefined reference to 'stderr'
./libcrypto.so: error: undefined reference to 'stdin'
./libcrypto.so: error: undefined reference to 'signal'
./libcrypto.so: error: undefined reference to 'tcsetattr'
./libcrypto.so: error: undefined reference to 'tcgetattr'
collect2: error: ld returned 1 exit status
make[2]: *** [link_app.gnu] Error 1
make[2]: Leaving directory `/home/Dokumenty/programowanie/supertuxkart/supertuxkart-git/android/obj/openssl'
make[1]: *** [test/buildtest_aes] Error 2
make[1]: Leaving directory `/home/Dokumenty/programowanie/supertuxkart/supertuxkart-git/android/obj/openssl'
make: *** [all] Error 2

@nurupo
Copy link

nurupo commented Jul 6, 2017

Have similar issue compiling different software, not openssl. Worked using previous Android NDK versions, but getting

../testing/DHT_test.c:208: error: undefined reference to 'stdin'
../toxcore/DHT.c:2404: error: undefined reference to 'rand'
../toxcore/DHT.c:1626: error: undefined reference to 'rand'
../toxcore/DHT.c:1629: error: undefined reference to 'rand'
../toxcore/DHT.c:1938: error: undefined reference to 'rand'
../toxcore/network.c:548: error: undefined reference to 'srand'

using the latest one.

Seems likely that something in Android NDK has changed, so probably not openssl issue.

@deveee did you find how to fix this?

@nurupo
Copy link

nurupo commented Jul 6, 2017

Ok, found how to temporary fix it.

When creating Android NDK toolchain using make_standalone_toolchain.py, pass --deprecated-headers as an argument. Found it reading NDK's changelog.

The fix is temporary because

Note: The deprecated headers will be removed in a future release, most likely r16. If they do not work for you, file bugs now.

So if these undefined reference errors are issues in OpenSSL, they should be fixed before new NDK comes out, and they are not OpenSSL bugs, then someone should file a bug to Google.

@levitte
Copy link
Member

levitte commented Jul 6, 2017

All those undefined references should have nothing to do with headers and everything to do with libraries you're linking with. Is it possible that you need to link with some additional library you haven't specified?

@nurupo
Copy link

nurupo commented Jul 6, 2017

Got my issue resolved in android/ndk#445 (comment).

@levitte
Copy link
Member

levitte commented Jul 6, 2017

Ok then

@levitte levitte closed this as completed Jul 6, 2017
@deveee
Copy link
Author

deveee commented Jul 6, 2017

Okay, but it looks that CFLAGS is not easy to set in openssl. And using clang gives another issue...

clang50: error: unknown argument: '-mandroid'

At least now I know the reason of these issues, thanks.

@nurupo
Copy link

nurupo commented Jul 6, 2017

Well, as a workaround, you could replace the gcc binary with a bash script file named gcc which calls clang instead.

e.g. save

#!/bin/sh
$ANDROID_TOOLCHAIN_DIR/arm-linux-androideabi-clang "$@"

as $ANDROID_TOOLCHAIN_DIR/arm-linux-androideabi-gcc, overwriting the original gcc.

If using clang doesn't work because openssl detects that it's clang and tries to use the unsupported -mandroid, then try copying gcc to gcc-original and saving

#!/bin/sh
$ANDROID_TOOLCHAIN_DIR/arm-linux-androideabi-gcc-original -D__ANDROID_API__=$API "$@"

as gcc. Don't forget to set $API.

neolit123 added a commit to neolit123/subsurface that referenced this issue Apr 29, 2018
Attempt to fix "undefined reference to 'stdout' by
passing --deprecated-headers when creating a toolchain.

ref:
openssl/openssl#3826 (comment)

Seems like a temporary fix.

Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com>
@chenwq3
Copy link

chenwq3 commented May 23, 2018

This can compile, I not test yet. Just posting here for reference.

CROSS_COMPILE=aarch64-linux-android- CC=clang ../openssl-1.1.0h/Configure --sysroot=/home/weiqi/android-ndk-r17/sysroot --sysroot=/home/weiqi/android-toolchain/sysroot --prefix=$(pwd)/prefix --openssldir=$(pwd)/prefix linux-aarch64

@ruCyberPoison
Copy link

Hello guys,

Well i have the same problem when i try to "make" openssl with ndk r17b released in june.

so anyone know how can i fix this ?
in r17b ?

rgds

@feliwir
Copy link

feliwir commented May 14, 2019

On a note here: even when OPENSSL_NO_STDIO is defined, the macro TEST_ENG_OPENSSL_RC4 is set, which causes a fprintf to stderr (In eng_openssl.c)

My OpenSSL version is 1.1.1b. The macro must be inside the no-stdio check:
https://github.com/openssl/openssl/blob/master/crypto/engine/eng_openssl.c#L30

So i suggest reopening this issue, or i can create a new issue if requested

@ManuelSchmitzberger
Copy link

I had the same issue.

stdin/stdout/stderr weren't added as variables until API 23.
I build the code for API 21, but I've built libopenssl.a for a later API level.

set minSdkVersion to 23 in the gradle file fixes the issue for me.

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

7 participants