Problems attempting to build oboe c++ library using cmake on windows - android

I am attempting to build 'oboe' on a windows machine using cmake (version 3.25.0) and a visual studio generator. The end goal is to create a c++ audio library that uses oboe as the back end for android, but as a first step simply geting oboe to build is the plan.
I have managed to succesfully generate build and use a static library with a few simple test functions using the method described below, but I run into errors when attempting to build oboe.
I have also managed to get oboe to build by using the method described in the documentation and
doing add_subdirectory etc. in the CMakeLists file of android studio. However I am trying to generate/ build using cmake outside of android studio.
The oboe repo is found here: https://github.com/google/oboe
The toolchain file I am using is: 'android.toolchain.cmake' included in the NDK at the location: ndk version/build/cmake/android.toolchain.cmake
I use a batch script to automate generating/ building to several different android ABI's, inspired by a similar shell script included with the oboe repo 'build_all_android.sh'. The .bat script I made is shown below:
#echo OFF
set BUILD_DIR=build
set ANDROID_NDK=C:\Microsoft\AndroidNDK\android-ndk-r23c
set GENERATOR="Visual Studio 17 2022"
set CMAKE_GENERATOR=-G %GENERATOR%
set CMAKE_TOOLCHAIN_FILE=-DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK%\build\cmake\android.toolchain.cmake
set CMAKE_SYSTEM_NAME=-DCMAKE_SYSTEM_NAME=Android
set EXTRA_CMAKE_ARGS=-DBUILD_SHARED_LIBS=true -DANDROID_TOOLCHAIN=clang -DANDROID_STL=c++_static
CALL :build_android armeabi-v7a ARM 16
CALL :build_android arm64-v8a ARM64 21
CALL :build_android x86_64 x64 21
CALL :build_android x86 x86 16
EXIT /B %ERRORLEVEL%
:build_android
set ABI_VERSION=%~1
set GENERATOR_PLATFORM=%~2
set MINIMUM_API_LEVEL=%~3
set CMAKE_ANDROID_ARCH_ABI=-DANDROID_ABI=%ABI_VERSION%
set ABI_BUILD_DIR=%BUILD_DIR%\%ABI_VERSION%
set CMAKE_GENERATOR_PLATFORM=-A %GENERATOR_PLATFORM%
set CMAKE_BUILD_DIR=-B %ABI_BUILD_DIR%
set CMAKE_MIN_API=-DANDROID_PLATFORM=android-%MINIMUM_API_LEVEL%
set CMAKE_ARGS=%CMAKE_BUILD_DIR% %CMAKE_ANDROID_ARCH_ABI% %CMAKE_GENERATOR% %CMAKE_GENERATOR_PLATFORM% %CMAKE_SYSTEM_NAME% %CMAKE_TOOLCHAIN_FILE% %CMAKE_MIN_API%
echo building for android ABI: %ABI_VERSION%
echo cmake arguments = %CMAKE_ARGS%
echo:
cmake %CMAKE_ARGS% %EXTRA_CMAKE_ARGS%
echo:
cmake --build %ABI_BUILD_DIR% --target ALL_BUILD
echo:
echo:
EXIT /B 0
When I run this using the ANDROID_NDK variable (line 3) pointing to the root of the up to date ndk that comes with the visual studio 2022 android tools, I get an error:
-- The C compiler identification is unknown
-- The CXX compiler identification is unknown
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - failed
-- Check for working C compiler: C:/Microsoft/AndroidNDK/android-ndk-r23c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
-- Check for working C compiler: C:/Microsoft/AndroidNDK/android-ndk-r23c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules/CMakeTestCCompiler.cmake:70 (message):
The C compiler
"C:/Microsoft/AndroidNDK/android-ndk-r23c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/user/Documents/Code Projects/oboe/build/x86/CMakeFiles/CMakeScratch/TryCompile-pp2ibg
Run Build Command(s):C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe cmTC_c21fb.vcxproj /p:Configuration=Debug /p:Platform=x86 /p:VisualStudioVersion=17.0 /v:m && MSBuild version 17.4.1+9a89d02ff for .NET Framework
ANDROID_HOME=C:\\Microsoft\AndroidSDK\25
ANDROID_SDK_ROOT=C:\\Microsoft\AndroidSDK\25
ANT_HOME=
JAVA_HOME=C:\Program Files\Android\jdk\jdk-8.0.302.8-hotspot\jdk8u302-b08
NDK_ROOT=C:\Microsoft\AndroidNDK\android-ndk-r23c
testCCompiler.c
In file included from <built-in>:349:
<command line>(1,9): warning : '__ANDROID_API__' macro redefined [-Wmacro-redefined] [C:\Users\user\Documents\Code Projects\oboe\build\x86\CMakeFiles\CMakeScratch\TryCompile-pp2ibg\cmTC_c21fb.vcxproj]
#define __ANDROID_API__ 1
^
<built-in>(342,9): note: previous definition is here
#define __ANDROID_API__ __ANDROID_MIN_SDK_VERSION__
^
1 warning generated.
ld: error: cannot open crtbegin_so.o: No such file or directory
ld: error: unable to find library -llog
ld: error: unable to find library -landroid
ld: error: cannot open crtend_so.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Application Type\Android\3.0\Android.Common.targets(125,5): error MSB6006: "clang.exe" exited with code 1. [C:\Users\user\Documents\Code Projects\oboe\build\x86\CMakeFiles\CMakeScratch\TryCompile-pp2ibg\cmTC_c21fb.vcxproj]
CMake will not be able to correctly generate this project.
and cmake fails to generate the project. I can actually get this to generate correctly, but only if I set the android NDK version within the cross-compilation options of visual studio to use the NDK bundled with my installation of Android studio, and also set the ANDROID_NDK variable of the batch script to point to the same root.
In this case, though cmake generates the project the build fails with a similar reason to the warning given above:
Building Custom Rule C:/Users/user/Documents/Code Projects/oboe/CMakeLists.txt
AAudioLoader.cpp
In file included from <built-in>:404:
<command line>(1,9): error : '__ANDROID_API__' macro redefined [-Werror,-Wmacro-redefined] [C:\Users\user\Documents\Co
de Projects\oboe\build\x86\oboe.vcxproj]
#define __ANDROID_API__ 16
^
<built-in>(394,9): note: previous definition is here
#define __ANDROID_API__ __ANDROID_MIN_SDK_VERSION__
^
1 error generated.
Thanks in advance for any help, it is much appreciated!

Your build fails because you instruct the compiler to view the warning '__ANDROID_API__' macro redefined as an error. And this warning seems to occur because Visual Studio still sets the macro __ANDROID_API__ instead of setting __ANDROID_MIN_SDK_VERSION__. I think that is a Visual Studio bug that was introduced when they started shipping the NDK 23 instead of 21.
EDIT:
This issue is being tracked here.

Related

Error when attempting to configure cmake for cross compilation to android

I have been trying to build a c++ library for android using cmake cross compilation.
The library itself is a trivial test I made purely for testing the androind build process.
I have been using the cmake gui (v 3.25.0) on a windows machine.
I use a visual studio 2019 generator in cmake and specify a toolchain file.
Unfortunately, I seem to get the same error whatever I try. I tried searching for similar problems and trouble shooting, but have so far been unable to make any progress. If anyone with more experience could lend a hand, I would be very grateful!
I have attempted setting many different variables in the toolchain file in an attempt to resolve the problem, but the basic version of what I am working with is:
set(CMAKE_SYSTEM_NAME Android)
set(CMAKE_ANDROID_ARCH_ABI armeabi-v7a)
set(CMAKE_ANDROID_NDK C:/Microsoft/AndroidNDK64/android-ndk-r16b/)
The error I run into happens whenever I configure cmake. The outut I get from cmake looks something like this:
Android: Targeting API '27' with architecture 'arm', ABI 'armeabi-v7a', and processor 'armv7-a'
Android: Selected Clang toolchain 'arm-linux-androideabi-clang' with GCC toolchain 'arm-linux-androideabi-4.9'
The C compiler identification is Clang 5.0.300080
The CXX compiler identification is Clang 5.0.300080
Detecting C compiler ABI info
Detecting C compiler ABI info - failed
Check for working C compiler: C:/Microsoft/AndroidNDK64/android-ndk-r16b//toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe
Check for working C compiler: C:/Microsoft/AndroidNDK64/android-ndk-r16b//toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - broken
CMake Error at C:/Program Files/CMake/share/cmake-3.25/Modules/CMakeTestCCompiler.cmake:70 (message):
The C compiler
"C:/Microsoft/AndroidNDK64/android-ndk-r16b//toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe"
is not able to compile a simple test program.
It fails with the following output:
Change Dir: C:/Users/username/Documents/Code Projects/Android Test/build/CMakeFiles/CMakeScratch/TryCompile-zqgcqm
Run Build Command(s):C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe cmTC_b0f1d.vcxproj /p:Configuration=Debug /p:Platform=x64 /p:VisualStudioVersion=16.0 /v:m && Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
ANDROID_HOME=C:\\Microsoft\AndroidSDK\25
ANT_HOME=C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Apps\apache-ant-1.9.3
JAVA_HOME=C:\Program Files\Eclipse Foundation\jdk-8.0.302.8-hotspot
NDK_ROOT=C:\\Microsoft\AndroidNDK64\android-ndk-r16b
testCCompiler.c
clang.exe : warning : argument unused during compilation: '-mthumb' [-Wunused-command-line-argument] [C:\Users\username\Documents\Code Projects\Android Test\build\CMakeFiles\CMakeScratch\TryCompile-zqgcqm\cmTC_b0f1d.vcxproj]
clang.exe : warning : argument unused during compilation: '-mfpu=vfpv3-d16' [-Wunused-command-line-argument] [C:\Users\username\Documents\Code Projects\Android Test\build\CMakeFiles\CMakeScratch\TryCompile-zqgcqm\cmTC_b0f1d.vcxproj]
clang.exe : warning : argument unused during compilation: '-mfloat-abi=softfp' [-Wunused-command-line-argument] [C:\Users\username\Documents\Code Projects\Android Test\build\CMakeFiles\CMakeScratch\TryCompile-zqgcqm\cmTC_b0f1d.vcxproj]
CLANGCOMPILE : error : unknown target CPU 'armv7-a' [C:\Users\username\Documents\Code Projects\Android Test\build\CMakeFiles\CMakeScratch\TryCompile-zqgcqm\cmTC_b0f1d.vcxproj]
CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
CMakeLists.txt:4 (project)
Configuring incomplete, errors occurred!
I initially used used the NDK version found in the android tools for visual studio found at: "C:/Microsoft/AndroidNDK64/android-ndk-r16b/"
as an NDK version.
I have also tried directly downloading the latest version of the NDK and pointing to that with CMAKE_ANDROID_NDK in the toolchain file, though this did not seem to make any change.
I have tried directly using the toolchain.cmake files found at "NDK/build/cmake/android.toolchain.cmake"
for both the NDK versions described above. This too gave the same error.
Any ideas what could be causing this or how to fix?
Ok, so I was misunderstanding a few things about cross-compiling to android.
First, if I want to be able to use the static library (e.g in android studio), I will need to generate and build a solution for more than one android ABI.
The ABI's to build for are: armeabi-v7a, arm64-v8a, x86_64, x86. I then need to check for each android ABI in the CMakeLists.txt file of Android studio (e.g. elseif(ANDROID_ABI STREQUAL arm64-v8a)) and swap out the location of the library to import to the build folder of that particular ABI.
As far as I am aware, it is unfortunately not possible to generate for all these ABI's as seperate platforms within the same visual studio solution. Given that, cmake must be run 4 seperate times to different build folders, each time targeting a different ABI and generator platform. To save the hassle of doing this manually, creating a batch (.bat) script to automate the process seems the best way to go. This will involve using cmake from the command line instead of the GUI version. The script can also be made to build the generated projects to save opening each one in visual studio and building there.
The batch script I have made to generate and build cross-compilation projects for android is as follows:
#echo OFF
set BUILD_DIR=build
set ANDROID_NDK=C:\Microsoft\AndroidNDK\android-ndk-r23c
set GENERATOR="Visual Studio 17 2022"
set CMAKE_GENERATOR=-G %GENERATOR%
set CMAKE_TOOLCHAIN_FILE=-DCMAKE_TOOLCHAIN_FILE=%ANDROID_NDK%\build\cmake\android.toolchain.cmake
set CMAKE_SYSTEM_NAME=-DCMAKE_SYSTEM_NAME=Android
set EXTRA_CMAKE_ARGS=-DBUILD_SHARED_LIBS=true -DANDROID_TOOLCHAIN=clang -DANDROID_STL=c++_static
CALL :build_android armeabi-v7a ARM 16
CALL :build_android arm64-v8a ARM64 21
CALL :build_android x86_64 x64 21
CALL :build_android x86 x86 16
EXIT /B %ERRORLEVEL%
:build_android
set ABI_VERSION=%~1
set GENERATOR_PLATFORM=%~2
set MINIMUM_API_LEVEL=%~3
set CMAKE_ANDROID_ARCH_ABI=-DANDROID_ABI=%ABI_VERSION%
set ABI_BUILD_DIR=%BUILD_DIR%\%ABI_VERSION%
set CMAKE_GENERATOR_PLATFORM=-A %GENERATOR_PLATFORM%
set CMAKE_BUILD_DIR=-B %ABI_BUILD_DIR%
set CMAKE_MIN_API=-DANDROID_PLATFORM=android-%MINIMUM_API_LEVEL%
set CMAKE_ARGS=%CMAKE_BUILD_DIR% %CMAKE_ANDROID_ARCH_ABI% %CMAKE_GENERATOR% %CMAKE_GENERATOR_PLATFORM% %CMAKE_SYSTEM_NAME% %CMAKE_TOOLCHAIN_FILE% %CMAKE_MIN_API%
echo building for android ABI: %ABI_VERSION%
echo cmake arguments = %CMAKE_ARGS%
echo:
cmake %CMAKE_ARGS% %EXTRA_CMAKE_ARGS%
echo:
cmake --build %ABI_BUILD_DIR% --target ALL_BUILD
echo:
echo:
EXIT /B 0
This worked for my simple test library, but I guess depending on the project the arguments to the cmake commands may need to be tweaked.

Unable to get qmake to cross compile correctly

I am new to this build system, but I've spent dozens of hours trying to get qmake + clang to produce a working android binary. I would appreciate any help or advice. Here is as simple an example as I can come up with:
First, here is a working build command. It gives me a shared object that I can call from android (with Unity, using C# native interops):
C:\Users\deltav\AppData\Local\Android\Sdk2\ndk\21.3.6528147\toolchains\llvm\prebuilt\windows-x86_64\bin\clang.exe ^
-target aarch64-none-linux-android21 -shared -v ^
-DANDROID_ABI=arm64-v8a -DANDROID_ARM_MODE=arm -DANDROID ^
M:\simpleExample\simpleExample.c ^
-o M:\simpleExample\libsimpleExample.so
Here is the verbose output of running that command: https://pastebin.com/18HcnDYh
On the other hand, here is the simpleExample.pro file that is NOT giving me a good binary: https://pastebin.com/wxrx6Myc
Here is the qmake output for building in release mode: https://pastebin.com/KWavwrb7
As you will know, qmake uses a kit to execute the project. My kit: https://imgur.com/a/Ehtmgin
The specific issue that has pushed me down this debugging path is from C# trying to load my shared object like this:
[DllImport("simpleExample")]
public static extern float getSpeedY();
The error that I get is this:
"DllNotFoundException: Unable to load DLL 'simpleExample': The
specified module could not be found."
Again, this error is not an issue if I just build from the CLI without qmake. I do not beleive this is a unity or C# error, as I worked the problem from that side first.
What I have tried so far:
I have used multiple ELF & DWARF tools to compare the ABIs of the generated binaries, which all told me the binaries were identical.
I tweaked and shaved down the clang calls that qmake generated until I got a vaild build command. Unfortunately I can't just replace qmake with the complile command because there are other projects that I need to apply this fix to.
QMake version 3.1
Ironically, CMake basically works out of the box.
Answer: Looking at the clang linking call, you can see QMake 3.1 was adding "libc++shared" as a dependency. I'm not sure why, as this was a C project.
The equivalent CMake project did not do this.
Packaging libc++shared with my binary fixed the issue.

Having trouble building a very simple OpenCV C++ .so library using CMake for use on Android

I am trying to use CMake to create a .so library that uses OpenCV for use on Android.
I have no prior experience with CMake before this. I got a couple things working with CMake so far. I successfully built and ran a simple OpenCV program for windows and I've also created a .so file that doesn't use OpenCV. I was able to successfully called that .so from a Unity program on Android. My goal is to create an OpenCV plugin for Unity. I turned to CMake because I tried making a simple .so in Visual Studios, but my Unity program couldn't find it (though I was able to create a .dll that used OpenCV for a windows Unity program using Visual Studios that worked).
I have both r19c Android NDK and OpenCV 4.5.2 Android SDK on my C drive.
My code file is test.cpp, and it very simply uses some OpenCV elements. It's as follows:
#include "opencv2/opencv.hpp"
extern "C" int get_number()
{
cv::Mat img(2,2, CV_8UC3, cv::Scalar(126,0,255));
cv::Size size = img.size();
int width = size.width;
return width;
}
I am thinking that my error may be in the CMakeLists.txt file, that I am probably pointing to the wrong OpenCV folders.
My CMakeLists.txt is:
cmake_minimum_required(VERSION 3.20)
set(OpenCV_DIR C:/OpenCVAndroid/sdk/native/jni/abi-arm64-v8a)
set(OpenCV_INCLUDE_DIRS C:/OpenCVAndroid/sdk/native/jni/include)
project( test )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_library( test SHARED test.cpp )
and I'm using a .bat file that has the following lines:
rmdir /s /q build
mkdir build
cd build
"C:/Program Files/CMake/bin/cmake.exe" ^
-S=C:\Users\m_knu\Desktop\test ^
-G"MinGW Makefiles" ^
-DCMAKE_BUILD_TYPE=Release ^
-DCMAKE_TOOLCHAIN_FILE=C:\r19c\android-ndk-r19c\build\cmake\android.toolchain.cmake ^
-DCMAKE_MAKE_PROGRAM=C:\r19c\android-ndk-r19c\prebuilt\windows-x86_64\bin\make.exe ^
-DANDROID_NDK=C:\r19c\android-ndk-r19c ^
-DANDROID_NATIVE_API_LEVEL=android-21 ^
-DANDROID_ABI=arm64-v8a ^
-DCMAKE_MODULE_PATH="C:/OpenCVAndroid/sdk/native/jni/abi-armeabi-v7a" ^
"C:/Program Files/CMake/bin/cmake.exe" --build .
pause
all three files are located in the same folder.
When I run the .bat file I get the following output:
C:\Users\m_knu\Desktop\test>rmdir /s /q build
C:\Users\m_knu\Desktop\test>mkdir build
C:\Users\m_knu\Desktop\test>cd build
C:\Users\m_knu\Desktop\test\build>"C:/Program Files/CMake/bin/cmake.exe" -S=C:\Users\m_knu\Desktop\test -G"MinGW Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_TOOLCHAIN_FILE=C:\r19c\android-ndk-r19c\build\cmake\android.toolchain.cmake -DCMAKE_MAKE_PROGRAM=C:\r19c\android-ndk-r19c\prebuilt\windows-x86_64\bin\make.exe -DANDROID_NDK=C:\r19c\android-ndk-r19c -DANDROID_NATIVE_API_LEVEL=android-21 -DANDROID_ABI=arm64-v8a -DCMAKE_MODULE_PATH="C:/OpenCVAndroid/sdk/native/jni/abi-armeabi-v7a"
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/r19c/android-ndk-r19c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/r19c/android-ndk-r19c/toolchains/llvm/prebuilt/windows-x86_64/bin/clang++.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found OpenCV: C:/OpenCVAndroid (found version "4.5.2")
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/m_knu/Desktop/test/build
C:\Users\m_knu\Desktop\test\build>"C:/Program Files/CMake/bin/cmake.exe" --build .
[ 50%] Building CXX object CMakeFiles/test.dir/test.cpp.o
[100%] Linking CXX shared library libtest.so
CMakeFiles/test.dir/test.cpp.o: In function `get_number':
C:\Users\m_knu\Desktop\test/test.cpp:5: undefined reference to `cv::Mat::Mat(int, int, int, cv::Scalar_<double> const&)'
C:\Users\m_knu\Desktop\test/test.cpp:9: undefined reference to `cv::Mat::~Mat()'
clang++.exe: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libtest.so] Error 1
make[1]: *** [CMakeFiles/test.dir/all] Error 2
make: *** [all] Error 2
C:\Users\m_knu\Desktop\test\build>pause
Press any key to continue . . .
As I mentioned earlier, my guess is that I've incorrectly referenced the OpenCV directories, but I wouldn't be surprised if I'm missing other things.

How do you update the GNU linker for an Android NDK?

I am working on a native Android project using NDK r12b. This NDK (and it looks like all others since) ships with a prebuilt GNU linker version 2.25. We have recently tried to pull up lots of our project's submodules which has introduced a build error that looks like it is caused by this bug in ld.
build error output:
/opt/android-ndk-r12b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: internal error in do_relocate_sections, at /usr/local/google/buildbot/src/android/gcc/toolchain/build/../binutils/binutils-2.25/gold/reloc.cc:953
collect2: error: ld returned 1 exit status
I thought I would attempt to update the linker but have had no luck finding prebuilt binaries. So I went down the rabbit hole of trying to compile ld/binutils myself. Either my Google skills are failing me, or documentation for doing this is truly rare or presumes the user has a lot of introductory knowledge that I don't have.
When building binutils 2.29.1 with target=arm-linux my application build errors out with this result:
/opt/android-ndk-r12b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin/ld: unrecognised emulation mode: armelf_linux_eabi
Supported emulations: armelf_linux armelf armelfb armelfb_linux
collect2: error: ld returned 1 exit status
For reference, the -V output of our current version of ld is:
me#linux-vm:/opt/android-ndk-r12b/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/arm-linux-androideabi/bin$ ./ld-2.25 -V
GNU gold (binutils-2.25-0666073 2.25.51.20141117) 1.11
Supported targets:
elf64-littleaarch64
elf64-bigaarch64
elf32-littleaarch64
elf32-bigaarch64
elf64-tradlittlemips
elf32-tradlittlemips-nacl
elf64-tradbigmips
elf32-tradlittlemips-nacl
elf32-tradlittlemips
elf32-tradlittlemips-nacl
elf32-tradbigmips
elf32-tradlittlemips-nacl
elf32-tilegx-be
elf64-tilegx-be
elf32-tilegx-le
elf64-tilegx-le
elf32-bigarm
elf32-bigarm-nacl
elf32-littlearm
elf32-littlearm-nacl
elf64-powerpcle
elf64-powerpc
elf32-powerpcle
elf32-powerpc
elf64-sparc
elf32-sparc
elf32-x86-64
elf32-x86-64-freebsd
elf32-x86-64-nacl
elf64-x86-64
elf64-x86-64-freebsd
elf64-x86-64-nacl
elf32-i386
elf32-i386-freebsd
elf32-i386-nacl
Supported emulations:
aarch64_elf64_le_vec
aarch64_elf64_be_vec
aarch64_elf32_le_vec
aarch64_elf32_be_vec
elf64-tradlittlemips
elf32-tradlittlemips-nacl
elf64-tradbigmips
elf32-tradlittlemips-nacl
elf32-tradlittlemips
elf32-tradlittlemips-nacl
elf32-tradbigmips
elf32-tradlittlemips-nacl
elf32tilegx_be
elf64tilegx_be
elf32tilegx
elf64tilegx
armelfb
armelfb_nacl
armelf
armelf_nacl
elf64lppc
elf64ppc
elf32lppc
elf32ppc
elf64_sparc
elf32_sparc
elf32_x86_64
elf32_x86_64_nacl
elf_x86_64
elf_x86_64_nacl
elf_i386
elf_i386_nacl
So apparently I'm missing some important configuration parameters. I also tried using an older (r8e) Android NDK's build/tools/build-gcc.sh script to build the entire compiler toolchain but with a newer binutils version. This resulted in an unknown build error:
me#linux-vm:/opt/android-ndk-r8e/build/tools$ ./build-gcc.sh --gmp-version=5.0.5 --mpfr-version=3.1.1 --mpc-version=1.0.1 --binutils-version=2.26
$(pwd)/src $(pwd) arm-linux-androideabi-4.7
To follow build in another terminal, please use: tail -F /tmp/ndk-me/build/toolchain/config.log
Using C compiler: gcc -m32
Using C++ compiler: g++ -m32
Sysroot : Copying: /opt/android-ndk-r8e/platforms/android-9/arch-arm --> /tmp/ndk-me/build/toolchain/prefix/sysroot
Configure: arm-linux-androideabi-4.7 toolchain build
Building : arm-linux-androideabi-4.7 toolchain [this can take a long time].
Error while building toolchain. See /tmp/ndk-me/build/toolchain/config.log
Last entries of config.log:
ar cru libintl.a bindtextdom.o dcgettext.o dgettext.o gettext.o finddomain.o loadmsgcat.o localealias.o textdomain.o l10nflist.o explodename.o dcigettext.o dcngettext.o dngettext.o ngettext.o plural.o plural-exp.o localcharset.o relocatable.o localename.o log.o osdep.o intl-compat.o
ranlib libintl.a
make[1]: Leaving directory `/tmp/ndk-me/build/toolchain/libbfd-binutils-2.26/intl'
At this point I'm just spinning my tires and trying to brute force success with different combinations of configuration parameters and source package versions. It seems as simple as adding emulation support for armelf_linux_eabi, but like I said, I have failed to find any documentation or guides that show how to do this. Surely there is a GNU wizard out there somewhere who could point me down a better path? Any help is appreciated!
I would try --enable-targets=all first. It is a bit of a big hammer, but maybe it helps you to avoid figuring out the exact target triplets you need (my guess would be arm-unknown-linux-eabi).

Checking preprocessor directives with Android Studio Gradle Build, NDK and CMake

I'm passing in preprocessor directives via CMakeLists.txt for the build of a native android library using android NDK.
add_definitions(-DMY_DIRECTIVE=1)
It would be great to double check that those preprocessor directives are actually finding their way into the calls to the compiler (llvm ?)
But the gradle build output doesn't seem to include the calls to the compiler, I just get:
Building C object CMakeFiles/my_project.dir/home/me/projects/my_proj/src/my_native.c.o
Is there a means to make the gradle output more verbose such that I can see the actual compiler calls and check those preprocessor directives are present?
The answer is to understand that Gradle utilises CMake to build the android NDK component (shared library) of an android project, and CMake utilises Ninja as a build system to handle the calls to the compiler. The compiler used by android NDK now defaults to LLVM->Clang.
So in order to actually see the Clang calls you have to find the build.ninja files for each target of your android project.
In my case I am only building for an armeabi-v7a target architecture. Therefore the relevant build.ninja files are found in:
/home/me/projects/my_proj/app/.externalNativeBuild/cmake/debug/armeabi-v7a
/home/me/projects/my_proj/app/.externalNativeBuild/cmake/release/armeabi-v7a
cd to either directory and run:
ninja -v
i.e. the -v option is the key to see all the calls to the clang compiler that the native build (android NDK) part of your android project generates.
Note if you have installed CMake via the android package manager, you may find that ninja is not installed in a location that is on your PATH. For me the ninja binary is located as follows:
~/Android/Sdk/cmake/3.6.3155560/bin/ninja
(same directory as cmake binary)
Therefore for me to see all the clang compiler calls for my android project's debug armeabi-v7a build I have to run:
cd /home/me/projects/my_proj/app/.externalNativeBuild/cmake/debug/armeabi-v7a
~/Android/Sdk/cmake/3.6.3155560/bin/ninja -v
Note if ninja tells you ninja: no work to do.
Then run:
~/Android/Sdk/cmake/3.6.3155560/bin/ninja clean
Relevant ninja documentation is -> https://ninja-build.org/manual.html#_extra_tools

Categories

Resources