-
Notifications
You must be signed in to change notification settings - Fork 196
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
Library can not be used in android (arm64) #523
Comments
Sorry for the long delay! Is this still a problem or did you find a solution? If it is still a problem I need to replicate the problem so I need the data of your environment (version numbers etc) and how you came to it, that is what were your individual steps. And yes, it is most likely a matter of build flags (probably |
Yes still not solved the problem. The library builds and can be used in Linux and Windows. We are trying to port the project using it to Android. I'm using latest NDK, and the triplet used is this one: All libraries required build in VCPKG properly. Even this library builds, I get both a static and a shared library. Thanks for your help. |
This is the port file used in VCPKG to build the library: vcpkg_from_github( if(VCPKG_TARGET_IS_WINDOWS)
else()
endif() file(INSTALL |
Any suggestion what needs to be changed in this "port" file to fix the problem ? As I mentioned, the port file and the library work for an x86 standard Linux build, the problem is only when trying to use the library on an Android ARM64 build, when I get the errors. The build is cross-compiled from Linux using the android NDK tools, which works properly for other libraries build., except this one so the toolchain is properly setup. |
I tried your triplet and port (you just changed There should be a file And please run |
Can you use the
to do so. |
I think this is the problem. Looking at objdump, for libtommath and the other libraries build in the same folder, it looks like libtommath is not cross-compiled but build for x86 ? See the architecture for other libs (all build with the same triplet, in the same environment). All are using same triplet/environment and I did not touch the port file for any libs. What is different which may explain something, the build triplet asks for "dynamic build". For libtommath the build generates both a static and a dynamic library (I think in Windows we just get the static one, this is why we link with the static one in every environment). I suppose the static one is also not cross-compiled. adrian@HX90-MINT:~/Dev/vcpkg/installed/arm64-android/lib$ objdump -f libtommath.so.1.2.0 libtommath.so.1.2.0: file format elf64-x86-64 adrian@HX90-MINT:~/Dev/vcpkg/installed/arm64-android/lib$ objdump -f libgtest.so libgtest.so: file format elf64-little adrian@HX90-MINT:~/Dev/vcpkg/installed/arm64-android/lib$ objdump -f libz.so libz.so: file format elf64-little adrian@HX90-MINT:~/Dev/vcpkg/installed/arm64-android/lib$ objdump -f libcrypto.so libcrypto.so: file format elf64-little adrian@HX90-MINT:~/Dev/vcpkg/installed/arm64-android/lib$ objdump -f libssl.so.1.1 libssl.so.1.1: file format elf64-little |
stdout-arm64-android.log |
build-out.log |
I will try later with the "develop" branch, if you think that fixes the problem. I tried ( changed the port file, remove, install libtommath again in vcpkg). I hope this used the modified port file (the file did not changed, it stayed as the modified one, I hope it did get used for the new install, I see in downloads a libtom package with 04e9... in name so probably did) but the objdump still shows an x86 build. I think the use of libtool is breaking the cross compiling, the other libs do not seem to use it. |
I did the dump for the static lib, and also for another static build one Goggle "benchmark". The "benchmark" lib is also build as static only even if the triplet requires dynamic build, but I don't think it uses libtool, and it is correct. Libtommath builds however for x86 not for ARM64. Can the build be fixed and not use libtool (just build the static lib same as benchmark ? I'm not familiar with the procedure. I also think that cross-compile with libtool is a known problem, not sure if it was solved or not) Here is the dump file: |
Thanks for the dumps, were helpful!
Yes, it is still not easy. The port-file does the standard build only. We would need to set I doubt it would be as easy as to just set BTW: your One of the main reasons for the complex build-process of LibTomMath is the broad support: about a dozen operating systems for about a dozen architectures. |
Can you please try out if using the add-cmake-support branch solves your issue? I guess this also simplifies your build recipe a lot. |
Thank I will try. I will have to move the project out of the vcpkg build and build it separately but if it solves the problem it's worth the effort. I have a combination of projects some are available in vcpkg (great!), other not. Most if not all of other projects I encountered are build using CMake. |
You are correct , the path to NDK is in the environment variable. In fact there is a good description here for building Android via VCPKG , and it works well for all other projects I tried. https://vcpkg.readthedocs.io/en/latest/users/android/ For the second question. of course. Would be great to get this fixed, and if works get the port updated in VCPKG also, may help others. The cross-compile problem can be in any environment not only Android (can be also for Apple M1, if same procedure is used). |
Thanks, I tried. It build without problems in Windows, Linux x86 and cross-compile properly this time in ARM64 Android. Using CMake really puts this project in line with most other ones. Would be nice if vcpkg guys will use this branch (or manage to fix the standard one), pretty sure that currently because of that libtool any cross-compile is broken. With "cmake branch": llvm-objdump -f libtommath.a libtommath.a(mp_2expt.c.o): file format ELF64-aarch64-little ... I managed to build my project using this lib. I see that a number of functions disappeared are they obsolete ? (they are still in master). |
Any chance that the "cmake branch" is going to get in the main ? Would simplify a lot of work. I switch between a few OS-es all other projects we include are CMake based. Current Visual Studio (using now 2022) has very good support, for CMake projects, you can get rid of that old VS2008 solution. Until this problem I did not pay to much atention, using vcpkg for supported projects, but looks like all works until it does not. |
Yes, definitely. Should be in develop pretty soon. When we'll get a new release is not clear yet... |
@atopavirgil does it work with the (original) "add-cmake-support" branch well enough? No need to meddle with the port-file anymore? Ok, ok, ok, I give up: we need I see the "add-cmake-support" makes good progress, nice! Took the liberty to make "test" work with the shared lib (setting of |
I can build the "cmake branch" yes ( all OS-es, including cross-compiling, cmake is good at this), but from what I understand it's going to be a long time until there is an "official release" with this changes on it (maybe I'm wrong, you guys know better...)..The problem is that tommath is available for some time in vcpkg , which is quite popular as can be used in multiple OS-es and the cross-compile build in there is broken, pretty sure others will hit the same problem sooner or later. I'm pretty sure that only "official releases" are included in vcpkg, so if an "easy" fix that can be implemented in the "port" file can be found, would be great, I'm sure would help others. If it requires using another branch, so needs to be build separately anyway, the CMake branch already solves the problem. For my own projects I start doing changes, adding flags to use tommath build in vcpkg or separately from sources. By the way, there is any replacement for mp_expt_u32 ? The code I'm trying to integrate is using this function, which is gone in the develop branch . There is some equivalent one ? I'm not even the one who wrote the code, I just integrate a project using this in a larger project. |
Yepp, feared that. ;-)
It is (1) The exact number is |
Thanks for the help. Out of context but related to CMake build, for building in Windows using Visual Studio (CMake projects), this is my batch build (I did not see it around so it may help others). This is to build the lib (any project in fact) from command line. Of course, you can just load the "folder" in VS IDE and build it from there, VS knows to deal with CMake projects. This uses the same output folder structure as VS does by default from IDE. It may help others. This script assumes that is run from a "subfolder" from the project root where CMakeList.txt is supposed to be. For Linux, Android build I'm using more or less similar Linux script files. As a note, do not use any CMake "generators" other than ninja. All old "VS" generators are obsolete, as Visual Studio itself uses the ninja when it builds CMake projects. In general VS assumes that for CMake projects we also use VCPKG as many open source projects are build via vcpkg, but for this project the build does not really require it except for the toolchain. SET mypath=%~dp0 SET prpath=%newpath:~0% echo Project path: %prpath% echo Building for Windows @Rem This must point to VCPKG location (may be different in another system ) @Rem echo VCPKG path: %vcpkg% @Rem This must point to VisualStudio 2022 vcvars64.bat location (may be different in another system) echo Building x64 Release... SET instd=%prpath%\out\install\x64-Release @Rem We must call cmake from the output build folder. Create it and go there echo Output build folder is: %cd% @Rem Use Cmake to create the cache file @Rem Use cmake to build, install and create the packages @Rem cmake --build . --target Packages |
i'm use ndk too,it can create static.a file ,but wen i use in .so, ,
ld: error: relocation R_AARCH64_LDST64_ABS_LO12_NC cannot be used against symbol 's_mp_rand_source'; recompile with -fPIC
ld: error: relocation R_AARCH64_ADR_PREL_PG_HI21 cannot be used against symbol 's_mp_rand_source'; recompile with -fPIC
ld: error: relocation R_AARCH64_LDST64_ABS_LO12_NC cannot be used against symbol 's_mp_rand_source'; recompile with -fPIC
ld: error: relocation R_AARCH64_LDST64_ABS_LO12_NC cannot be used against symbol 's_mp_rand_source'; recompile with -fPIC
|
This should be fixed now. Please update to 1.3.0 and report any potential bugs by opening a new issue or post other questions to that release in #575 |
Not sure why, maybe some building flags. The library is build using VCPKG and works under Windows and Linux x64. However build using an android triplet when linked in an execurable or another shared library getting this for a static build:
/home/adrian/Dev/android/android-ndk-r23b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/21/liblog.so -llog -landroid -static-libstdc++ -latomic -lm && :
ld: error: /home/cc/Dev/vcpkg/installed/arm64-android/lib/libtommath.a(bn_mp_abs.o) is incompatible with aarch64linux
ld: error: /home/cc/Dev/vcpkg/installed/arm64-android/lib/libtommath.a(bn_mp_add.o) is incompatible with aarch64linux
ld: error: /home/cc/Dev/vcpkg/installed/arm64-android/lib/libtommath.a(bn_mp_and.o) is incompatible with aarch64linux
ld: error: /home/cc/Dev/vcpkg/installed/arm64-android/lib/libtommath.a(bn_mp_clear.o) is incompatible with aarch64linux
...
If a dynamic build is used, same aerror but reffering to the full lib.
Any build flags missing ? Does the library work under arm64 ?
The text was updated successfully, but these errors were encountered: