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 error in android-ndk-r19c #973

Closed
Miteshmakwana73 opened this issue Apr 30, 2019 · 17 comments
Closed

compilation error in android-ndk-r19c #973

Miteshmakwana73 opened this issue Apr 30, 2019 · 17 comments
Labels

Comments

@Miteshmakwana73
Copy link

I am getting this error while running the android studio project, gradle is working okay

ui_openssl.c:(.text+0x68): undefined reference to `stdin'
ui_openssl.c:(.text+0x6c): undefined reference to `stdin'
ui_openssl.c:(.text+0x9c): undefined reference to `stderr'
ui_openssl.c:(.text+0xa0): undefined reference to `stderr'
/home/jenya1/Downloads/baresip-studio-master/app/src/main/cpp/../../../../distribution/openssl/lib/arm64-v8a/libcrypto.a(libcrypto-lib-ui_openssl.o): In function `close_console':
ui_openssl.c:(.text+0x374): undefined reference to `stdin'
ui_openssl.c:(.text+0x378): undefined reference to `stdin'
ui_openssl.c:(.text+0x3a0): undefined reference to `stderr'
ui_openssl.c:(.text+0x3a4): undefined reference to `stderr'

full Log error
error.txt

@enh
Copy link
Contributor

enh commented Apr 30, 2019

stdin/stdout/stderr weren't added as variables until API 23. fread_unlocked/fwrite_unlocked until 28.

you're building this code for API 21 (--target=aarch64-none-linux-android21), but it looks like you've built libcrypto.a and libbaresip.a for a later API level.

@Miteshmakwana73
Copy link
Author

after updating minsdk 23 it worked

but getting a new error
new error.txt

@enh
Copy link
Contributor

enh commented May 1, 2019

nope, that's the error i mentioned in the second sentence of my original reply. that library was built with target API 28, like i said.

@Miteshmakwana73
Copy link
Author

Miteshmakwana73 commented May 1, 2019

this is my make file

# -------------------- VALUES TO CONFIGURE --------------------

# Path to your Android NDK (must be r19 or higher)
NDK_PATH  :=  /usr/local/android-ndk-r19

# Android API level
API_LEVEL := 28

# Set default from following values: [armeabi-v7a, arm64-v8a]
ANDROID_TARGET_ARCH := armeabi-v7a

# Directory where libraries and include files are instelled
OUTPUT_DIR := /usr/src/baresip-studio/distribution

so I have to set API_LEVEL=23 ?

@enh
Copy link
Contributor

enh commented May 1, 2019

if you want to run on API level 23, yes, you need to build for API level 23. otherwise the compiler thinks it can use things that weren't available until 24/25/26/27/28, and your code won't run on 23 or earlier.

@ericQiang
Copy link

this is my make file

# -------------------- VALUES TO CONFIGURE --------------------

# Path to your Android NDK (must be r19 or higher)
NDK_PATH  :=  /usr/local/android-ndk-r19

# Android API level
API_LEVEL := 28

# Set default from following values: [armeabi-v7a, arm64-v8a]
ANDROID_TARGET_ARCH := armeabi-v7a

# Directory where libraries and include files are instelled
OUTPUT_DIR := /usr/src/baresip-studio/distribution

so I have to set API_LEVEL=23 ?

@Miteshmakwana73
Hi, have you resolved ?
now ,i get the error

jni/../../../src/util_ini.cpp:208: error: undefined reference to 'fread_unlocked'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libmtn_test.so] Error 1

I want compile a apk that run in a embedded device which have android8.1.
i known that android8.1 corresponding to the api level 27.

like @enh said. the function fread_unlocked supported by api 28 or later.
that means i can only compile with sdk-27(because the android 8.1 just support api level 27), but the sdk 27 cannot support 'fread_unlocked'.

what should i do?

ps. i develop with qt for android. and android-ndk-r19c.
微信截图_20190712151940
微信截图_20190712151931

微信截图_20190712151151
i choose android-27 android-28 and android-29, all throw the same error

jni/../../../src/util_ini.cpp:208: error: undefined reference to 'fread_unlocked'

best regards.

@DanAlbert
Copy link
Member

DanAlbert commented Jul 12, 2019

What are you using to build? Can you share your build.gradle/cmakelists.txt/android.mk? If you're targeting 28+ and have that problem then something has gone wrong, but we don't have enough information to even guess what it would be.

@ericQiang
Copy link

@DanAlbert
Thanks for your reply.

My environment is: Qt13.0 + jdk1.8.0_181 + android-sdk(27,28,29) + android-ndk-r19c. suck as the following picture show.
微信截图_20190712170401

the following files come from my test project. can you point out what's my fault?
thanks.
the following files with a .txt suffix for uploading.
gradle-wrapper.properties.txt
gradlew.bat.txt
gradlew.txt
AndroidManifest.xml.txt
build.gradle.txt
mtn_test.pro.txt
Makefile.txt

@ericQiang
Copy link

ericQiang commented Jul 12, 2019

oh, @DanAlbert I found the reason.
in the makefile

LFLAGS = --sysroot=C:\Android\android-ndk-r19c/platforms/android-21/...

I changed the platform in the gui interface of QT. but that not take effect. I changed the android-21 to android-28 manually, and it worked.

But unfortunately, the apk cannot run on my device. because my device is android 8.1(api level27).

So, if or not i compile a standalone "fread_unlocked" and linked into my project?
or how should we do when we use "fread_unlocked" in project with api level older 28,?

Thanks

@enh
Copy link
Contributor

enh commented Jul 12, 2019

if you just replace fread_unlocked with fread, you'll have code that works on older devices. it'll be slightly slower because it'll do the extra locking, but that's unavoidable on older devices.

@ericQiang
Copy link

if you just replace fread_unlocked with fread, you'll have code that works on older devices. it'll be slightly slower because it'll do the extra locking, but that's unavoidable on older devices.

@enh
Thanks for your reply.
now it seems that i have to use your method.

regards

@linuxaged
Copy link

stdin/stdout/stderr weren't added as variables until API 23. fread_unlocked/fwrite_unlocked until 28.

why ndk try to link fread_unlocked/fwrite_unlocked when i use std::fwrite?

@enh-google
Copy link
Collaborator

why ndk try to link fread_unlocked/fwrite_unlocked when i use std::fwrite?

it doesn't. you're using fread_unlocked/fwrite_unlocked somewhere. you can find out where by using objdump on your .o/.so files.

@amir28
Copy link

amir28 commented Jul 17, 2022

I had this issue in compiling linux kernel for android 10(api 29).

drivers/built-in.o: In function `_save_testing_data':
/mnt/Android/Phone/oneplus-nord-n10/bd/downloads/sdm630-kernel/drivers/input/touchscreen/gt1x/test_function.c:1065: undefined reference to `fwrite_unlocked'
/mnt/Android/Phone/oneplus-nord-n10/bd/downloads/sdm630-kernel/drivers/input/touchscreen/gt1x/test_function.c:1087: undefined reference to `fwrite_unlocked'
/mnt/Android/Phone/oneplus-nord-n10/bd/downloads/sdm630-kernel/drivers/input/touchscreen/gt1x/test_function.c:939: undefined reference to `fwrite_unlocked'
/mnt/Android/Phone/oneplus-nord-n10/bd/downloads/sdm630-kernel/drivers/input/touchscreen/gt1x/test_function.c:953: undefined reference to `fwrite_unlocked'
/mnt/Android/Phone/oneplus-nord-n10/bd/downloads/sdm630-kernel/drivers/input/touchscreen/gt1x/test_function.c:1104: undefined reference to `fwrite_unlocked'
drivers/built-in.o:/mnt/Android/kernel/drivers/input/touchscreen/gt1x/test_function.c:1112: more undefined references to `fwrite_unlocked' follow
make[1]: *** [/mnt/Android/linuxkernel/Makefile:1001: vmlinux] Error 1

adding this in Makefile solved it.

subdir-ccflags-y += \
        -fno-builtin-fwrite \
        -Wno-sizeof-pointer-div

@enh-google
Copy link
Collaborator

@amir28 --- can you file a new bug for that? i think that's an unrelated issue that i'm not sure we've checked (if clang is automatically "optimizing" fwrite() to fwrite_unlocked() without paying attention to API level).

@rprichard
Copy link
Collaborator

They're compiling a kernel, so AFAIK there shouldn't be an Android API level. sdm630 has been around a while -- is @amir28 using gcc or clang to build it?

I think the existence of fflush(nullptr) would make an fwrite -> fwrite_unlocked optimization impractical in general.

I'd guess that a header is defining fwrite to fwrite_unlocked, but then I don't know why -fno-builtin-fwrite would fix it.

@android android locked as resolved and limited conversation to collaborators Jul 19, 2022
@DanAlbert
Copy link
Member

The bug originally reported here was user error. If you think you've found a bug, please file a new one (we need the information asked for in the template). Locking to encourage that.

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

No branches or pull requests

8 participants