NDK: libm static linking - android

I have a problem during try to compile sources with recent android-9 x86 platform.
Primary question: why static library libm.a and dynamic libm.so are different?
Problem is i've try to compile:
/path/to/android-ndk-r8/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc --sysroot=/path/to/android-ndk-r8/platforms/android-9/arch-x86 -I/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/include -I/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/libs/x86/include -L/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/lib -L/path/to/android-ndk-r8/platforms/android-9/arch-x86/usr/lib -static /path/to/gcc_4_4_6_release/gcc/testsuite/gcc.dg/complex-5.c -std=c99 -O -ffloat-store -o ./complex-5.exe -lm
but I have undefined reference:
/tmp/cc78CsCp.o: In function main': complex-5.c:(.text+0x1a2):
undefined reference tofeclearexcept' complex-5.c:(.text+0x1b3):
undefined reference to `fetestexcept' collect2: ld returned 1 exit
status
pwd: /path/to/android-ndk-r8/platforms/android-9/arch-x86/usr/lib
ls libm*
libm.a libm.so
It exists, but if we look with nm for feclearexcept, it isn't present within static library.
Ok, just try to remove -static flag.
/path/to/android-ndk-r8/toolchains/x86-4.4.3/prebuilt/linux-x86/bin/i686-android-linux-gcc --sysroot=/path/to/android-ndk-r8/platforms/android-9/arch-x86 -I/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/include -I/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/libs/x86/include -L/path/to/android-ndk-r8/sources/cxx-stl/gnu-libstdc++/lib -L/path/to/android-ndk-r8/platforms/android-9/arch-x86/usr/lib /path/to/gcc_4_4_6_release/gcc/testsuite/gcc.dg/complex-5.c -std=c99 -O -ffloat-store -o ./complex-5.exe -lm
Ok. That the question: why they are differ? I need static linkage, I don't want to force usage of dynamic linkage with -Wl,-Bdynamic -lm. By the way: regular linux libm.a and libm.so contains similar list of functions.

Related

Undefined Function outside Header Error Android NDK

I am currently linking a static library to my Android Project which contains the functions I want to use, the problem that occurs is when I call a function from the static library in Android Project, and the function definition is in a .cpp file, my build fails. If that function is defined in a header through a class for example, the project compiles and runs.
The .cpp file is compiled with the definition and the project still outputs an error of no definition.
Edit: I noticed a new error message of the function outputting that it's not an ELF object.
Android Project Calls Function from Static Library:
Example.h
void example();
Example.cpp
void example()
{
} //Error
Example.h
class example
{
public:
void example()
{
}//Compiles
}
Error:
"C:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/bin\ld" -z noexecstack --warn-shared-textrel -z now -z relro --hash-style=both --enable-new-dtags --eh-frame-hdr -m elf_i386 -shared -o "Debug\\Android-x86\\x86\\libProject.so" "C:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../sysroot/usr/lib/i686-linux-android/16\crtbegin_so.o" "-LC:\\ProjectFolder\\ProjectFolder\\Debug\\Android-x86\\x86" "-LC:\\ProjectFolder\\ProjectFolder\\StaticLibrary" "-LC:\\ProjectFolder\\ProjectFolder\\StaticLibrary\\Source" -u ANativeActivity_onCreate "-LC:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\lib64\clang\9.0.9\lib\linux\i386" "-LC:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../lib/gcc/i686-linux-android/4.9.x" "-LC:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../sysroot/usr/lib/i686-linux-android/16" "-LC:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../sysroot/usr/lib/i686-linux-android" "-LC:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../lib/gcc/i686-linux-android/4.9.x/../../../../i686-linux-android/lib" "-LC:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../sysroot/usr/lib" --exclude-libs libgcc.a --exclude-libs libatomic.a -z noexecstack -z relro --build-id=md5 --no-undefined -z now "Debug\\Android-x86\\Main.o" -lEGL -lGLESv2 -landroid -latomic -lStaticLibrary "C:\\Users\\User\\AppData\\Local\\Android\\Sdk\\ndk\\21.4.7075529\\toolchains\\llvm\\prebuilt\\windows-x86_64\\sysroot\\usr\\lib\\i686-linux-android\\libc++_shared.so" -soname=libProject.so -lc++ -lm -lgcc -ldl -lc -lgcc -ldl "C:\Users\User\AppData\Local\Android\Sdk\ndk\21.4.7075529\toolchains\llvm\prebuilt\windows-x86_64\bin/../sysroot/usr/lib/i686-linux-android/16\crtend_so.o"
1>C:\ProjectFolder\ProjectFolder\ProjectFolder/Main.cpp(10): error : undefined reference to 'FunctionName()'
1>C:\ProjectFolder\ProjectFolder\ProjectFolder/Main.cpp(10): error : clang++: error: linker command failed with exit code 1
The linker clearly says undefined reference to 'FunctionName()'
In other words it can't find the source file with FunctionName() implementation. Make sure the file is compiled or implementation is placed in the same namespace with the same name (in this particular case without any namespace).
I tried moving all my static library files to a new project and it seems that the previous static library Visual Studio project was corrupted, after moving over to a new clean project everything compiled.

How to build boost for android as shared library with c++11 support

I am trying to build boost_1.60.0 (as shared library) for android with c++11 support. I am using the latest ndk (currently android-ndk-r10e). The build host is Windows-10.
This is for a non-opensource project. So as far as I understand I cannot use gnustl_shared, and I need to use c++_shared as the android c++ runtime.
my project-config.jam looks like this:
androidNDKRoot = c:/android-ndk-r10e ;
using gcc : android :
$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ :
<root>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/
<compileflags>-MMD
<compileflags>-MP
<compileflags>-MF
<compileflags>-fpic
<compileflags>-ffunction-sections
<compileflags>-funwind-tables
<compileflags>-fstack-protector
<compileflags>-no-canonical-prefixes
<compileflags>-march=armv5te
<compileflags>-mtune=xscale
<compileflags>-msoft-float
<compileflags>-fno-rtti
<compileflags>-mthumb
<compileflags>-Os
<compileflags>-g
<compileflags>-DNDEBUG
<compileflags>-fomit-frame-pointer
<compileflags>-fno-strict-aliasing
<compileflags>-finline-limit=64
<compileflags>-IC:/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include
<compileflags>-IC:/android-ndk-r10e/sources/cxx-stl/llvm-libc++/../llvm-libc++abi/libcxxabi/include
<compileflags>-IC:/android-ndk-r10e/sources/cxx-stl/llvm-libc++/../../android/support/include
<compileflags>-IC:/android-ndk-r10e/platforms/android-9/arch-arm/usr/include
<compileflags>-Wa,--noexecstack
<compileflags>-Wformat
<compileflags>-Werror=format-security
<compileflags>-DUNIX
<compileflags>-DANDROID
<compileflags>-Wl,--no-undefined
<cxxflags>-fexceptions
<linkflags>-lc++_shared
<archiver>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi-ar
<ranlib>$(androidNDKRoot)/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi-ranlib
;
the build command is:
b2 --toolset=gcc-android cxxflags="-std=c++11 " --prefix=..\boost_android_arm --builddir=./boost_android_arm/builddir target-os=linux --with-filesystem define=BOOST_FILESYSTEM_VERSION=3 link=shared runtime-link=shared threading=multi
In order to determine the parameters in the project-config.jam I've build a sample shared library using the ndk-build, get its debug messages, and extracted the compile and link commands it uses.
compile:
C:\android-ndk-r10e\toolchains\arm-linux-androideabi-4.8\prebuilt\windows-x86_64\bin\arm-linux-androideabi-g++.exe,C:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ -MMD -MP -MF ./obj/local/armeabi/objs/someLib/./Unity1.o.d -fpic -ffunction-sections -funwind-tables -fstack-protector -no-canonical-prefixes -march=armv5te -mtune=xscale -msoft-float -fno-exceptions -fno-rtti -mthumb -Os -g -DNDEBUG -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -Ijni/../../library/../../../../ -Ijni/../../library/../../../../src/ -IC:/android-ndk-r10e/sources/cxx-stl/llvm-libc++/libcxx/include -IC:/android-ndk-r10e/sources/cxx-stl/llvm-libc++/../llvm-libc++abi/libcxxabi/include -IC:/android-ndk-r10e/sources/cxx-stl/llvm-libc++/../../android/support/include -Ijni/../../library -DANDROID -DHAVE_CONFIG_H -DSESTEK_ANDROID_XERCES_HACK -Wa,--noexecstack -Wformat -Werror=format-security -std=c++11 -fno-strict-aliasing -frtti -fexceptions -DUNIX -DANDROID -IC:/android-ndk-r10e/platforms/android-9/arch-arm/usr/include -c jni/../../library/./Unity1.cpp -o ./obj/local/armeabi/objs/someLib/./Unity1.o,...)
link:
C:\android-ndk-r10e\toolchains\arm-linux-androideabi-4.8\prebuilt\windows-x86_64\bin\arm-linux-androideabi-g++.exe,C:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++ -Wl,-soname,libsomeLib.so -shared --sysroot=C:/android-ndk-r10e/platforms/android-9/arch-arm ./obj/local/armeabi/objs/someLib/./Unity1.o -lgcc ./obj/local/armeabi/libc++_shared.so -no-canonical-prefixes -Wl,--no-undefined -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -mthumb -lc -lm -o ./obj/local/armeabi/libsomeLib.so,...)
For brevity I've only build filesystem for this trial but in the end I plan to build at least thread, filesystem, date_time, asio and log libraries.
Finally the error I get is as follows.
...patience...
...found 660 targets...
...updating 13 targets...
gcc.compile.c++ bin.v2\libs\system\build\gcc-android\release\target-os-linux\threading-multi\error_code.o
gcc.link.dll bin.v2\libs\system\build\gcc-android\release\target-os-linux\threading-multi\libboost_system-gcc-mt-1_60.so.1.60.0
c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot open crtbegin_so.o: No such file or directory
c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lrt
c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot open crtend_so.o: No such file or directory
c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lc++_shared
c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lstdc++
c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lm
c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lc
c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -ldl
c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: cannot find -lc
c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: bin.v2\libs\system\build\gcc-android\release\target-os-linux\threading-multi\error_code.o: requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC
c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: bin.v2\libs\system\build\gcc-android\release\target-os-linux\threading-multi\error_code.o: requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC
c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld.exe: error: bin.v2\libs\system\build\gcc-android\release\target-os-linux\threading-multi\error_code.o: requires unsupported dynamic reloc R_ARM_REL32; recompile with -fPIC
./boost/system/detail/error_code.ipp:458: error: undefined reference to '__dso_handle'
./boost/system/detail/error_code.ipp:464: error: undefined reference to '__dso_handle'
./boost/system/detail/error_code.ipp:158: error: undefined reference to '__dso_handle'
collect2.exe: error: ld returned 1 exit status
"c:/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/windows-x86_64/bin/arm-linux-androideabi-g++" -o "bin.v2\libs\system\build\gcc-android\release\target-os-linux\threading-multi\libboost_system-gcc-mt-1_60.so.1.60.0" -shared -Wl,--start-group "bin.v2\libs\system\build\gcc-android\release\target-os-linux\threading-multi\error_code.o" -Wl,-Bstatic -Wl,-Bdynamic -lrt -Wl,--end-group -lc++_shared -pthread
...failed gcc.link.dll bin.v2\libs\system\build\gcc-android\release\target-os-linux\threading-multi\libboost_system-gcc-mt-1_60.so.1.60.0...
...skipped <pstage\lib>libboost_system-gcc-mt-1_60.so.1.60.0 for lack of <pbin.v2\libs\system\build\gcc-android\release\target-os-linux\threading-multi>libboost_system-gcc-mt-1_60.so.1.60.0...
gcc.compile.c++ bin.v2\libs\filesystem\build\gcc-android\release\target-os-linux\threading-multi\codecvt_error_category.o
gcc.compile.c++ bin.v2\libs\filesystem\build\gcc-android\release\target-os-linux\threading-multi\operations.o
gcc.compile.c++ bin.v2\libs\filesystem\build\gcc-android\release\target-os-linux\threading-multi\path.o
gcc.compile.c++ bin.v2\libs\filesystem\build\gcc-android\release\target-os-linux\threading-multi\path_traits.o
gcc.compile.c++ bin.v2\libs\filesystem\build\gcc-android\release\target-os-linux\threading-multi\portability.o
gcc.compile.c++ bin.v2\libs\filesystem\build\gcc-android\release\target-os-linux\threading-multi\unique_path.o
gcc.compile.c++ bin.v2\libs\filesystem\build\gcc-android\release\target-os-linux\threading-multi\utf8_codecvt_facet.o
gcc.compile.c++ bin.v2\libs\filesystem\build\gcc-android\release\target-os-linux\threading-multi\windows_file_codecvt.o
...skipped <pbin.v2\libs\filesystem\build\gcc-android\release\target-os-linux\threading-multi>libboost_filesystem-gcc-mt-1_60.so.1.60.0 for lack of <pbin.v2\libs\system\build\gcc-android\release\target-os-linux\threading-multi>libboost_system-gcc-mt-1_60.so.1.60.0...
...skipped <pstage\lib>libboost_filesystem-gcc-mt-1_60.so.1.60.0 for lack of <pbin.v2\libs\filesystem\build\gcc-android\release\target-os-linux\threading-multi>libboost_filesystem-gcc-mt-1_60.so.1.60.0...
...failed updating 1 target...
...skipped 3 targets...
...updated 9 targets...
The error tells that it needs the directory to find the necessary libraries, but the problem is that under android ndk there are several files with names rt and crtbegin_so.o and such. I guess I need to make the compiler determine the correct directory itself.
With all being said what I need actually is to build boost shared libraries for android with c++11 support. So I may accept your help either by pointing me in the right direction using the above build parameters or providing me a working sample so I can work out the details myself.
Oh also one more thing: if I use link=static instead of link=shared in the build command the build succeeds. But I have not tried the produced static libraries.
Building Boost on Linux using the NDK
I know you're asking about Windows, but I wanted to do this on macOS and it failed with nearly the exact error. I finally broke down and did it on my linode server it worked without a problem. This says to me that they aren't really doing a good job of testing other platforms. Compiling static only on macOS works as you also discovered on Windows.
Point of reference
NDK R13
Boost 1.62.0
Tested with clang++; g++ also works
If you're wondering why I'm using clang, the Release Notes have the following message:
GCC is no longer supported. It will not be removed from the NDK just
yet, but is no longer receiving backports. It cannot be removed until
after libc++ has become stable enough to be the default, as some parts
of gnustl are still incompatible with Clang. It will likely be removed
after that point.
user-config.jam
I placed this file in my home directory. Yuck.
androidNDKRoot = /path/to/ndk-R13-standalone ;
using clang : android
:
$(androidNDKRoot)/bin/arm-linux-androideabi-clang++
:
;
Modifying libtool.m4 in boost to avoid versioning of the libraries
libtool.m4 under tools/build/src/engine/boehm_gc/libtool.m4 in the boost source has no reference to android and you'll need to change version_type=linux in the section linux*) to version_type=none. This will cause symbolic links to appear without the version number appended to the end linked to the versioned shared libraries in the output.
Building
Target OS MUST be android to avoid the -lrt flag being passed which will cause shared linking to fail.
./b2 \
-d+2 \
-j 4 \
--reconfigure \
target-os=android \
toolset=clang-android \
include=${ANDROID_NDK_STANDALONE}/include/c++/4.9.x \
link=static,shared \
variant=debug,release \
threading=multi \
--layout=versioned \
--prefix=${BOOST_INSTALL_DIR} \
install
A relevant information is here (Boost for Android), where they have been able to successfully build the shared libraries, but it seems that the resulting files have a version suffix which android can't handle. Also one can't just rename the binary because the file name is hardcoded in it. One way out, as per the last post, is to set the variable version_type to none (version_type=none) in the linux section of file. In your case, the build setup could be a little different, but it may be worthwhile to take a look at the changes they made at that discussion.
user-config.jam
If you want to find boost from cmake(find_package) you must use the version of compiler, and not android like the top answer, in your user-config.jam like below according to boost doc.
androidNDKRoot = /path/to/ndk-R13-standalone ;
using clang : 8.0.1
:
$(androidNDKRoot)/bin/arm-linux-androideabi-clang++
:
;
My answer for me in future. How to build latest Boost(1.79.0) with latest NDK(24.0) on Windows PC for Android.
Go to your downloaded boost_1_79_0 unpacked directory and build b2 tool:
.\bootstrap.bat
Check b2 tools is ready:
b2 --version
B2 4.8-git <-- possible output
create file user-config.jam in %HOME% directory with content like that(example):
using clang : arm64 : c\:/Users/l_chayka/Downloads/android-ndk-r24/toolchains/llvm/prebuilt/windows-x86_64/bin/aarch64-linux-android21-clang++.cmd : <cxxflags>-std=c++20 ;
using clang : arm : c\:/Users/l_chayka/Downloads/android-ndk-r24/toolchains/llvm/prebuilt/windows-x86_64/bin/armv7a-linux-androideabi21-clang++.cmd : <cxxflags>-std=c++20 ;
using clang : x86 : c\:/Users/l_chayka/Downloads/android-ndk-r24/toolchains/llvm/prebuilt/windows-x86_64/bin/i686-linux-android21-clang++.cmd : <cxxflags>-std=c++20 ;
using clang : x86_64 : c\:/Users/l_chayka/Downloads/android-ndk-r24/toolchains/llvm/prebuilt/windows-x86_64/bin/x86_64-linux-android21-clang++.cmd : <cxxflags>-std=c++20 ;
Go to boost root and try to build for every Android architecture (arm, arm64, x86, x86_64) example:
c:\Users\l_chayka\Downloads\boost_1_79_0>b2.exe toolset=clang-x86_64 target-os=android link=static variant=debug threading=multi --layout=versioned --prefix=c:/boost-x64_86/ install
c:\Users\l_chayka\Downloads\boost_1_79_0>b2.exe toolset=clang-x86 target-os=android link=static variant=debug threading=multi --layout=versioned --prefix=c:/boost-x86/ install
c:\Users\l_chayka\Downloads\boost_1_79_0>b2.exe toolset=clang-arm target-os=android link=static variant=debug threading=multi --layout=versioned --prefix=c:/boost-arm/ install
c:\Users\l_chayka\Downloads\boost_1_79_0>b2.exe toolset=clang-arm64 target-os=android link=static variant=debug threading=multi --layout=versioned --prefix=c:/boost-arm64/ install
Now check you instalation prefix path.

cross compile c program for android

I have a c program that uses -lpcap, -lm, and -lpthread. I see the libraries in /usr/arm-linuxgnueabi/lib/. However, if I compile using the command
arm-linux-gnueabi-gcc -static *.c -L/usr/arm-linux-gnueabi/lib/ -lpcap -lm -lpthread -o dumps/forandroid
It gives the following error:
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find crt1.o: No such file or directory<br>
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find crti.o: No such file or directory<br>
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find -lpcap<br>
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find -lm<br>
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find -lpthread
/usr/lib/gcc-cross/arm-linux-gnueabi/4.7/../../../../arm-linux-gnueabi/bin/ld: cannot find -lc<br>
collect2: error: ld returned 1 exit status
How can I give the library path properly? I am trying to compile the program for android emulator running android 5.1. I am using mint 17.2 64 bit amd machine.
I solved the problem using ndk toolchain. I compiled libpcap for arm-linux and used the library. The following command does the job:
arm-linux-androideabi-gcc --sysroot=/home/shahrear/Android/ndk/platforms/android-21/arch-arm -fpie -fpic -I./pcap -I. *.c -L./lib -pie -lm -lpcap -o dumps/forandroid

android GMP cross compilation

I'm on debian/amd64 and I want to cross-compile GMP for android 2.2 using NDK-7b. I took the source code from [gmplib](hg clone http://gmplib.org:8000/gmp-5.0 gmp).
I configured it with:
./configure --enable-shared --host=arm-linux-androideabi --prefix=/home/fabien/android/spica/ndk-standalone-8 CFLAGS="-v -march=armv5te -mtune=xscale -msoft-float -Wl,-rpath,lib/ -DANDROID -ffunction-sections -funwind-tables -fstack-protector -funswitch-loops -finline-limit=300 -Wall -O3 -nodefaultlibs -fPIC -shared -Wl,--no-allow-shlib-undefined" PKG_CONFIG_PATH="/home/fabien/android/spica/ndk-standalone-8/lib/pkgconfig" LDFLAGS="-Wl,-rpath-link -Wl,/home/fabien/android/spica/ndk-standalone-8/lib -L/home/fabien/android/spica/ndk-standalone-8/lib"
I modified the file config.h by setting:
/* Define to 1 if you have the `obstack_vprintf' function. */
#ifndef ANDROID
#define HAVE_OBSTACK_VPRINTF 1
#endif
/* Define to 1 if you have the `localeconv' function. */
#ifndef ANDROID
#define HAVE_LOCALECONV 1
#endif
/* Define to 1 if you have the `vsnprintf' function and it works properly. */
#ifndef ANDROID
#define HAVE_VSNPRINTF 1
#endif
I updated the SUBDIRS parameter as follows in Makefile:
SUBDIRS = tests mpn mpz mpq mpf printf scanf cxx mpbsd demos tune
It seems to compile when I run make:
libtool: link: (cd ".libs" && rm -f "libgmp.so" && ln -s "libgmp.so.10.0.5" "libgmp.so")
libtool: link: ( cd ".libs" && rm -f "libgmp.la" && ln -s "../libgmp.la" "libgmp.la" )
But when I run "make check", the linker seems lost:
/../../../../arm-linux-androideabi/bin/ld: warning: ld-linux.so.3, needed by /home/fabien/android/spica/sources/gmp/.libs/libgmp.so, not found (try using -rpath or -rpath-link)
t-bswap.o:(.ARM.exidx.text.main+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
./.libs/libtests.a(misc.o):(.ARM.exidx.text.align_pointer+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
.
.
.
refmpn.c:(.text.refmpn_get_str+0xb8): undefined reference to `__aeabi_uidiv'
refmpn.c:(.text.refmpn_get_str+0x238): undefined reference to `__aeabi_ui2d'
refmpn.c:(.text.refmpn_get_str+0x250): undefined reference to `__aeabi_dmul'
refmpn.c:(.text.refmpn_get_str+0x254): undefined reference to `__aeabi_d2uiz'
./.libs/libtests.a(refmpn.o):(.ARM.exidx.text.refmpn_get_str+0x0): undefined reference to `__aeabi_unwind_cpp_pr0'
/home/fabien/android/spica/sources/gmp/.libs/libgmp.so: undefined reference to `abort#GLIBC_2.4'
/home/fabien/android/spica/sources/gmp/.libs/libgmp.so: undefined reference to `puts#GLIBC_2.4'
Any hints ?
This error is due to the fact that the file that contains these helper functions (these are GCC helper functions) is not being included when the linker creates the target. To fix this, please add the libgcc.a (which contains the GCC helper function definitions) into the linker flags.
As for the location of libgcc.a, assuming gcc version arm-linux-androideabi-4.4.3, it will be
$NDK_ROOT/toolchains/arm-linux-androideabi-4.4.3/prebuilt/linux-x86/lib/gcc/arm-linux-androideabi/4.4.3/libgcc.a
This will NOT fix the following errors(which seem to be related to the GNU libc being missing):
.libs/libgmp.so: undefined reference to `abort#GLIBC_2.4'
.libs/libgmp.so: undefined reference to `puts#GLIBC_2.4'
The above 2 errors will always show up as android uses the Bionic libc, and not the GNU libc
Note: This method will fix similar issues on all systems, not just Android.

Building native library with standalone toolchain android arm

I am trying to build libraw as a Android shared library. It looks the lib is too complex to use with Android.mk etc, or better: I am not capable yet of doing that.
I tried the route of using a standalone toolchain from the NDK, but I am getting stuck when compiling this lib.
This is the path I take to compile the lib. Please point out if I am making obvious errors:
I downloaded the ndk.
ran: make-standalone-toolchain.sh
Added the bin folder of that standalone toolchain as first item in my PATH.
Ran ./configure with --host=arm-linux-androideabi. This succeeded
Ran make, here it crashed very fast.
LibRaw-0.14.4$ make
depbase=`echo internal/dcraw_common.lo | sed 's|[^/]*$|.deps/&|;s|\.lo$||'`;\
/bin/bash ./libtool --tag=CXX --mode=compile arm-linux-androideabi-g++ -DPACKAGE_NAME=\"LibRaw\" -DPACKAGE_TARNAME=\"libraw\" -DPACKAGE_VERSION=\"0.14.4\" -DPACKAGE_STRING=\"LibRaw\ 0.14.4\" -DPACKAGE_BUGREPORT=\"info#libraw.org\" -DPACKAGE_URL=\"http://www.libraw.org\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I. -I/usr/local/include -g -O2 -MT internal/dcraw_common.lo -MD -MP -MF $depbase.Tpo -c -o internal/dcraw_common.lo internal/dcraw_common.cpp &&\
mv -f $depbase.Tpo $depbase.Plo
libtool: compile: arm-linux-androideabi-g++ -DPACKAGE_NAME=\"LibRaw\" -DPACKAGE_TARNAME=\"libraw\" -DPACKAGE_VERSION=\"0.14.4\" "-DPACKAGE_STRING=\"LibRaw 0.14.4\"" -DPACKAGE_BUGREPORT=\"info#libraw.org\" -DPACKAGE_URL=\"http://www.libraw.org\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -I. -I/usr/local/include -g -O2 -MT internal/dcraw_common.lo -MD -MP -MF internal/.deps/dcraw_common.Tpo -c internal/dcraw_common.cpp -fPIC -DPIC -o internal/.libs/dcraw_common.o
internal/dcraw_common.cpp: In member function 'void LibRaw::read_shorts(ushort*, int)':
internal/dcraw_common.cpp:119: error: 'swab' was not declared in this scope
internal/dcraw_common.cpp: In member function 'void LibRaw::write_ppm_tiff()':
internal/dcraw_common.cpp:9235: error: 'swab' was not declared in this scope
make: *** [internal/dcraw_common.lo] Error 1
I doubt this error message is helpfull here at stackoverflow, but I am left wondering if I should have applied some additional flags or configuration to get this to work?
Note that I am able to compile this lib succesfully if just compiling for my system without crosscompiling. (linux 32bit).
When I am looking to a instruction for building GDAL for Android (here), it uses a additional setting of LIBS="-lsupc++ -lstdc++". This links the STL and C++ exceptions?
However, when I set those before running my configure I get immediately errors like:
configure:3018: checking whether the C++ compiler works
configure:3040: arm-linux-androideabi-g++ conftest.cpp -lsupc++ -lstdc++ >&5
/tmp/android-chain/bin/../lib/gcc/arm-linux-androideabi/4.4.3/../../../../arm-linux-androideabi/bin/ld: cannot find -lsupc++
collect2: ld returned 1 exit status
So, I am a bit stuck. Someone an idea?
I had to add an implementation of the swab function, since the NDK does not have that one.
Afterwards this compiled fine (but I used the crystax ndk).
A better way toolwise was to just use a Android.mk file and use ndk-build to compile it.
Linker error from the bottom of your question occurs because make-standalone-toolchain.sh from NDK r7 creates incomplete toolchain (it misses some libraries including libsupc++.a). I recommend you try making a toolchain from one of previous NDK releases (r6b should be fine).

Categories

Resources