Recent

Author Topic: Android NDK under Linux  (Read 5800 times)

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Android NDK under Linux
« on: December 29, 2015, 01:22:09 pm »
I'm trying to get fpc run for Android. First question is about the cross-compiler: When I have a working arm crosscompiler (make all crosszipinstall OS_TARGET=linux CPU_TARGET=arm), is this ppcrossarm able to compile for Android as well? Otherwise the names "ppcrossarm" would be the same.

Anyway, with both versions I cannot compile a simple Hello World example. Android NDK is installed (Arch Linux extracts it to /opt/...) and with some fiddeling it compiles but the linker doesn't work.

Quote from: fpc -Tandroid -Parm test.pas
Hint: End of reading config file /home/ht/.fpc.cfg
Free Pascal Compiler version 3.0.0 [2015/11/27] for arm
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Android for ARMEL
Compiling test.pas
Assembling hello
Linking test
/usr/local/bin/arm-android-ld: error: link.res:78:8: syntax error, unexpected STRING
/usr/local/bin/arm-android-ld: fatal error: unable to parse script file link.res
test.pas(4,23) Error: Error while linking
test.pas(4,23) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcarm returned an error exitcode
But arm-android-ld is my arm-linux toolchain!

And when I run ld directly
Quote from: /opt/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld test.o
test.o:test.pas:function main: error: undefined reference to 'FPC_INITIALIZEUNITS'
test.o:test.pas:function main: error: undefined reference to 'fpc_get_output'
test.o:test.pas:function main: error: undefined reference to 'fpc_write_text_shortstr'
test.o:test.pas:function main: error: undefined reference to 'FPC_IOCHECK'
test.o:test.pas:function main: error: undefined reference to 'fpc_writeln_end'
test.o:test.pas:function main: error: undefined reference to 'FPC_IOCHECK'
test.o:test.pas:function main: error: undefined reference to 'FPC_DO_EXIT'
test.o:test.pas:INITFINAL: error: undefined reference to 'INIT$_$SYSTEM'
test.o:test.pas:FPC_THREADVARTABLES: error: undefined reference to 'THREADVARLIST_$SYSTEM'
Most likely that was thought too easy.

I also struggle with the right path to the libraries in order to add those to my fpc.cfg. There are several lib folders in the NDK.
Quote
#ifdef cpuarm

#ifdef android
-Fl/opt/android-ndk/platforms/android-4/arch-arm/usr/lib
#endif

#ifdef linux
-Xd
-Fl/usr/local/arm/lib
-Fl/usr/local/arm/libc/usr/lib
...

And last but not least I wonder why the SDK should be installed at all. The wiki is not too verbose with explanations.

tl;dr;
1. How do I setup the right linker for fpc to manage both arm-linux and arm-android toolchains?
2. What is the right folder for libraries (-Fl) in the NDK?
Lazarus 1.7 (SVN) FPC 3.0.0

ykot

  • Full Member
  • ***
  • Posts: 141
Re: Android NDK under Linux
« Reply #1 on: December 29, 2015, 04:59:07 pm »
You don't need SDK to be installed. At least in my case, I don't and still can compile to both Android targets.

In my case, I just extracted NDK contents (changed extension to 7z to avoid self-extractor) to: "/data1/android/android-ndk" (/data1 in my case is a different hard-drive)

Then, commands to build Android/ARM target (inside fpc folder) are:
Code: [Select]
make clean crossall OS_TARGET=android CPU_TARGET=arm CROSSOPT="-CpARMv7a -CfVFPv3_D16 -OpARMv7a -OoFastMath -O3 -XX -Xs -CX" CROSSBINDIR="/data1/android/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin" BINUTILSPREFIX=arm-linux-androideabi-
sudo make crossinstall OS_TARGET=android CPU_TARGET=arm

Similarly, for Intel target:
Code: [Select]
make clean crossall OS_TARGET=android CPU_TARGET=i386 CROSSOPT="-CpCoreI -CfSSE3 -OpCoreI -OoFastMath -O3 -XX -Xs -CX" CROSSBINDIR="/data1/android/android-ndk/toolchains/x86-4.9/prebuilt/linux-x86_64/bin" BINUTILSPREFIX=i686-linux-android-
sudo make crossinstall OS_TARGET=android CPU_TARGET=i386

I'm using seed compiler installed in "/usr/local/bin/", which is FPC 3.0.0. Once I build all the possible targets (including Android), I replace it with new compiler. Here's my script to do so:
Code: [Select]
#!/bin/sh
set -e
sudo cp -av /usr/local/bin/ppcx64 /usr/local/bin/ppcx64.initial
sudo ln -s -f /usr/local/lib/fpc/3.1.1/ppcx64 /usr/local/bin/ppcx64
sudo cp /etc/fpc.cfg /etc/fpc.cfg.initial
sudo cp -av ./fpc.cfg /etc/fpc.cfg
And the script to get back to seed compiler (in case I want to update from SVN and rebuild all targets again):
Code: [Select]
#!/bin/sh
sudo cp /etc/fpc.cfg.initial /etc/fpc.cfg || exit 1
sudo cp -av /usr/local/bin/ppcx64.initial /usr/local/bin/ppcx64 || exit 1

These scripts are located in my "/data1/dev/" folder. I also have fresh "fpc.cfg" there, which first script will copy to overwrite seed's "fpc.cfg". It's contents are (search for Android related parts, including "-Fl" flag):
Code: [Select]
#
# Config file generated by fpcmkcfg on 22-7-15 - 09:56:06
# Example fpc.cfg for Free Pascal Compiler
#

# ----------------------
# Defines (preprocessor)
# ----------------------

#
# nested #IFNDEF, #IFDEF, #ENDIF, #ELSE, #DEFINE, #UNDEF are allowed
#
# -d is the same as #DEFINE
# -u is the same as #UNDEF
#

#
# Some examples (for switches see below, and the -? helppages)
#
# Try compiling with the -dRELEASE or -dDEBUG on the commandline
#

# For a release compile with optimizes and strip debuginfo
#IFDEF RELEASE
  -O2
  -Xs
  #WRITE Compiling Release Version
#ENDIF

# For a debug version compile with debuginfo and all codegeneration checks on
#IFDEF DEBUG
  -gl
  -Crtoi
  #WRITE Compiling Debug Version
#ENDIF

# assembling
#ifdef darwin
# use pipes instead of temporary files for assembling
-ap
# path to Xcode 4.3+ utilities (no problem if it doesn't exist)
-FD/Applications/Xcode.app/Contents/Developer/usr/bin
#endif

# ----------------
# Parsing switches
# ----------------

# Pascal language mode
#      -Mfpc      free pascal dialect (default)
#      -Mobjfpc   switch some Delphi 2 extensions on
#      -Mdelphi   tries to be Delphi compatible
#      -Mtp       tries to be TP/BP 7.0 compatible
#      -Mgpc      tries to be gpc compatible
#      -Mmacpas   tries to be compatible to the macintosh pascal dialects
#
# Turn on Object Pascal extensions by default
#-Mobjfpc

# Assembler reader mode
#      -Rdefault  use default assembler
#      -Ratt      read AT&T style assembler
#      -Rintel    read Intel style assembler
#
# All assembler blocks are AT&T styled by default
#-Ratt

# Semantic checking
#      -S2        same as -Mobjfpc
#      -Sc        supports operators like C (*=,+=,/= and -=)
#      -Sa        include assertion code.
#      -Sd        same as -Mdelphi
#      -Se<x>     error options. <x> is a combination of the following:
#         <n> : compiler stops after <n> errors (default is 1)
#         w   : compiler stops also after warnings
#         n   : compiler stops also after notes
#         h   : compiler stops also after hints
#      -Sg        allow LABEL and GOTO
#      -Sh        Use ansistrings
#      -Si        support C++ styled INLINE
#      -Sk        load fpcylix unit
#      -SI<x>     set interface style to <x>
#         -SIcom    COM compatible interface (default)
#         -SIcorba  CORBA compatible interface
#      -Sm        support macros like C (global)
#      -So        same as -Mtp
#      -Sp        same as -Mgpc
#      -Ss        constructor name must be init (destructor must be done)
#      -Sx        enable exception keywords (default in Delphi/ObjFPC modes)
#
# Allow goto, inline, C-operators, C-vars
-Sgic

# ---------------
# Code generation
# ---------------

# Uncomment the next line if you always want static/dynamic units by default
# (can be overruled with -CD, -CS at the commandline)
#-CS
#-CD

# Set the default heapsize to 8Mb
#-Ch8000000

# Set default codegeneration checks (iocheck, overflow, range, stack)
#-Ci
#-Co
#-Cr
#-Ct

# Optimizer switches
# -Os        generate smaller code
# -Oa=N      set alignment to N
# -O1        level 1 optimizations (quick optimizations, debuggable)
# -O2        level 2 optimizations (-O1 + optimizations which make debugging more difficult)
# -O3        level 3 optimizations (-O2 + optimizations which also may make the program slower rather than faster)
# -Oo<x>     switch on optimalization x. See fpc -i for possible values
# -OoNO<x>   switch off optimalization x. See fpc -i for possible values
# -Op<x>     set target cpu for optimizing, see fpc -i for possible values

#ifdef darwin
#ifdef cpui386
-Cppentiumm
-Oppentiumm
#endif
#endif

# -----------------------
# Set Filenames and Paths
# -----------------------

# Both slashes and backslashes are allowed in paths

# path to the messagefile, not necessary anymore but can be used to override
# the default language
#-Fr/usr/local/lib/fpc/$fpcversion/msg/errore.msg
#-Fr/usr/local/lib/fpc/$fpcversion/msg/errorn.msg
#-Fr/usr/local/lib/fpc/$fpcversion/msg/errores.msg
#-Fr/usr/local/lib/fpc/$fpcversion/msg/errord.msg
#-Fr/usr/local/lib/fpc/$fpcversion/msg/errorr.msg

# searchpath for units and other system dependent things
-Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget
-Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/*
-Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/rtl

#IFDEF FPCAPACHE_1_3
-Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/httpd13/
#ELSE
#IFDEF FPCAPACHE_2_0
-Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/httpd20
#ELSE
-Fu/usr/local/lib/fpc/$fpcversion/units/$fpctarget/httpd22
#ENDIF
#ENDIF

# searchpath for fppkg user-specific packages
-Fu~/.fppkg/lib/fpc/$fpcversion/units/$FPCTARGET/*

# path to the gcclib
#ifdef cpui386
-Fl/usr/lib/gcc/x86_64-linux-gnu/4.9/32
#endif
#ifdef cpux86_64
-Fl/usr/lib/gcc/x86_64-linux-gnu/4.9
#endif

# searchpath for libraries
#-Fl/usr/local/lib/fpc/$fpcversion/lib
#-Fl/lib;/usr/lib
-Fl/usr/local/lib/fpc/$fpcversion/lib/$FPCTARGET

# searchpath for tools
-FD/usr/local/lib/fpc/$fpcversion/bin/$FPCTARGET

#IFNDEF CPUI386
#IFNDEF CPUAMD64
#DEFINE NEEDCROSSBINUTILS
#ENDIF
#ENDIF

#IFNDEF Linux
#DEFINE NEEDCROSSBINUTILS
#ENDIF

# binutils prefix for cross compiling
#IFDEF FPC_CROSSCOMPILING
#IFDEF NEEDCROSSBINUTILS
  -XP$FPCTARGET-
#ENDIF
#ENDIF

#IFDEF ANDROID
#UNDEF NEEDCROSSBINUTILS
#ENDIF

# -------------
# Linking
# -------------

# generate always debugging information for GDB (slows down the compiling
# process)
#      -gc        generate checks for pointers
#      -gd        use dbx
#      -gg        use gsym
#      -gh        use heap trace unit (for memory leak debugging)
#      -gl        use line info unit to show more info for backtraces
#      -gv        generates programs tracable with valgrind
#      -gw        generate dwarf debugging info
#
# Enable debuginfo and use the line info unit by default
#-gl

# always pass an option to the linker
#-k-s

# Always strip debuginfo from the executable
-Xs


# -------------
# Miscellaneous
# -------------

# Write always a nice FPC logo ;)
-l

# Verbosity
#      e : Show errors (default)       d : Show debug info
#      w : Show warnings               u : Show unit info
#      n : Show notes                  t : Show tried/used files
#      h : Show hints                  s : Show time stamps
#      i : Show general info           q : Show message numbers
#      l : Show linenumbers            c : Show conditionals
#      a : Show everything             0 : Show nothing (except errors)
#      b : Write file names messages   r : Rhide/GCC compatibility mode
#          with full path              x : Executable info (Win32 only)
#      v : write fpcdebug.txt with     p : Write tree.log with parse tree
#          lots of debugging info
#
# Display Info, Warnings and Notes
-viwn
# If you don't want so much verbosity use
#-vw
# multiarch library search path
-Fl/usr/lib/$fpctarget-*

#IFDEF CPUI386
-Fl/usr/lib32
-Fl/usr/lib/i386-linux-gnu
#ENDIF

#IFDEF LINUX
#IFDEF CPUARM
-XParm-linux-gnueabihf-
-Fl/data1/dev/pi-lib
-CpARMv6
-CfVFPv2
-OoFastMath
-dFPC_ARMHF
#-CaEABIHF
#ENDIF
#ENDIF

#IFDEF ANDROID
#IFDEF CPUARM
-XParm-linux-androideabi-
-Fl/data1/android/android-ndk/platforms/android-21/arch-arm/usr/lib
-FD/data1/android/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
-OoFastMath
-CpARMv7a
-CfVFPv3_D16
-OpARMv7a
#ENDIF
#IFDEF CPU386
-XPi686-linux-android-
-Fl/data1/android/android-ndk/platforms/android-21/arch-x86/usr/lib
-FD/data1/android/android-ndk/toolchains/x86-4.9/prebuilt/linux-x86_64/bin
-OoFastMath
-CpCoreI
-CfSSE3
-OpCoreI
#ENDIF
#ENDIF

#IFDEF embedded
-OoFastMath
-XX
-CX
-OoNoStackFrame
#IFDEF cpuarm
-XParm-none-eabi-
#ENDIF
#IFDEF cpuavr
-XPavr-
#ENDIF
#ENDIF

# Third party units should be installe in a, multi-arch compatible location.
# Units should be installed in /usr/lib/$fpctarget-gnu/fp-units-2.6.2/$pkg/.
# Ech fp-units package should install a configuration file called $pkg.cfg in
#CFGDIR /etc/fpc-$fpcversion.cfg.d/$fpctarget

That assumes you installed seed compiler to "/usr/local/bin"; if you've put it to "usr/bin" (which FPC wants to do by default), then it's slightly trickier, few paths above need to be adjusted.

P.S. I also do "sudo ln -s -f /usr/local/lib/fpc/3.1.1/ppcrossarm /usr/local/bin/ppcrossarm" and "sudo ln -s -f /usr/local/lib/fpc/3.1.1/ppcross386 /usr/local/bin/ppcross386" for other targets (Linux/x86 and Linux/ARM), which also applies to Android.
« Last Edit: December 29, 2015, 05:03:36 pm by ykot »

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Android NDK under Linux
« Reply #2 on: December 29, 2015, 05:31:47 pm »
Hm... no success here. With the same fpc and fpc.cfg now, I still get errors, the wrong linker is used, and running the linker directly doesn't work too.
Quote
make clean crossall crosszipinstall OS_TARGET=android CPU_TARGET=arm CROSSOPT="-CpARMv7a -CfVFPv3_D16 -OpARMv7a -OoFastMath -O3 -XX -Xs -CX" CROSSBINDIR="/opt/android-ndk/toolchains/arm-li
nux-androideabi-4.9/prebuilt/linux-x86_64/bin/" BINUTILSPREFIX=arm-linux-androideabi-

Quote from: more .fpc.cfg
#ifdef cpuarm

#ifdef android
-XParm-linux-androideabi-
-Fl/opt/android-ndk/platforms/android-21/arch-arm/usr/lib
-FD/opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
-OoFastMath
-CpARMv7a
-CfVFPv3_D16
-OpARMv7a
#endif

#ifdef linux
...

Quote from: fpc -Tandroid -Parm test.pas
Hint: End of reading config file /home/ht/.fpc.cfg
Free Pascal Compiler version 3.0.0 [2015/11/27] for arm
Copyright (c) 1993-2015 by Florian Klaempfl and others
Target OS: Android for ARMEL
Compiling test.pas
Assembling hello
Linking test
/usr/local/bin/arm-android-ld: error: link.res:78:8: syntax error, unexpected STRING
/usr/local/bin/arm-android-ld: fatal error: unable to parse script file link.res
test.pas(4,23) Error: Error while linking
test.pas(4,23) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted
Error: /usr/bin/ppcarm returned an error exitcode

Quote from: more link.res
SEARCH_DIR(/opt/android-ndk/platforms/android-21/arch-arm/usr/lib/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/rtl/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/unzip/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-stl/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-extra/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-passrc/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-net/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/zlib/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-fpcunit/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/libgd/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/oracle/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/libpng/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/ibase/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/rtl-unicode/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fpmkunit/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fftw/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/dblib/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/httpd24/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/postgres/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-base/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-sdo/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/gdbm/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/bzip2/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/jni/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-sound/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/openssl/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/regexpr/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-res/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fppkg/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/tcl/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/imagemagick/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/hash/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-async/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/symbolic/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/rtl-console/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-registry/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/pasjpeg/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/rtl-objpas/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-json/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-db/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fastcgi/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-xml/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-image/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/libtar/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/pcap/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/sqlite/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/numlib/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-process/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/fcl-js/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/odbc/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/chm/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/mysql/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/rtl-extra/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/paszlib/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/hermes/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/units/arm-android/httpd22/)
SEARCH_DIR(/usr/lib/fpc/3.0.0/)
INPUT(
/usr/lib/fpc/3.0.0/units/arm-android/rtl/prt0.o
/opt/android-ndk/platforms/android-21/arch-arm/usr/lib/crtbegin_dynamic.o
test.o
/usr/lib/fpc/3.0.0/units/arm-android/rtl/system.o
)
GROUP(
-lc
)
INPUT(
/opt/android-ndk/platforms/android-21/arch-arm/usr/lib/crtend_android.o
)
SECTIONS
{
  .data           :
  {
    KEEP (*(.fpc .fpc.n_version .fpc.n_links))
  }
}
INSERT BEFORE .data1

All .o files from the link.res exists.

Quote from: /opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-ld -o test.out /usr/lib/fpc/3.0.0/units/arm-android/rtl/prt0.o /opt/android-ndk/platforms/android-21/arch-arm/usr/lib/crtbegin_dynamic.o test.o /usr/lib/fpc/3.0.0/units/arm-android/rtl/system.o /opt/android-ndk/platforms/android-21/arch-arm/usr/lib/crtend_android.o
/usr/lib/fpc/3.0.0/units/arm-android/rtl/prt0.o(.text+0x64): error: undefined reference to 'exit'
/opt/android-ndk/platforms/android-21/arch-arm/usr/lib/crtbegin_dynamic.o:crtbrand.c:function _start: error: undefined reference to '__libc_init'
/opt/android-ndk/platforms/android-21/arch-arm/usr/lib/crtbegin_dynamic.o:crtbrand.c:function atexit: error: undefined reference to '__cxa_atexit'
« Last Edit: December 29, 2015, 05:35:39 pm by Ocye »
Lazarus 1.7 (SVN) FPC 3.0.0

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Android NDK under Linux
« Reply #3 on: December 29, 2015, 06:00:30 pm »
One more observation. When I run ppas.sh (unmodified) I get:

Quote
/usr/bin/ld: skipping incompatible /opt/android-ndk/platforms/android-21/arch-arm/usr/lib/crtbegin_dynamic.o when searching for /opt/android-ndk/platforms/android-21/arch-arm/usr/lib/crtbegin_dynamic.o

This file has a ARMv5 attributes

Quote from: readelf -A /opt/android-ndk/platforms/android-21/arch-arm/usr/lib/crtbegin_dynamic.o
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "5TE"
  Tag_CPU_arch: v5TE
  Tag_ARM_ISA_use: Yes
  Tag_THUMB_ISA_use: Thumb-1
  Tag_ABI_PCS_wchar_t: 4
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: int
  Tag_ABI_optimization_goals: Aggressive Speed

So I wonder if all the cross options are right here.
Lazarus 1.7 (SVN) FPC 3.0.0

ykot

  • Full Member
  • ***
  • Posts: 141
Re: Android NDK under Linux
« Reply #4 on: December 29, 2015, 07:18:47 pm »
Where did you get "arm-android-ld" linker from? Looks like an unofficial third-party tool.

One more observation. When I run ppas.sh (unmodified) I get:

Quote
/usr/bin/ld: skipping incompatible /opt/android-ndk/platforms/android-21/arch-arm/usr/lib/crtbegin_dynamic.o when searching for /opt/android-ndk/platforms/android-21/arch-arm/usr/lib/crtbegin_dynamic.o
This is also a wrong linker (ld).

Normally, you should be using arm-linux-androideabi-ld as per BINUTILSPREFIX flag I've mentioned earlier. Just get official Android NDK from Google, download it from this page.

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Android NDK under Linux
« Reply #5 on: December 29, 2015, 08:55:29 pm »
Where did you get "arm-android-ld" linker from? Looks like an unofficial third-party tool.

Arch resp. AUR pulls it directly from Google (http://dl.google.com/android/ndk/${pkgname}-$pkgver-linux-x86_64.bin with pkgname=android-ndk & pkgver=r10e).
Lazarus 1.7 (SVN) FPC 3.0.0

ykot

  • Full Member
  • ***
  • Posts: 141
Re: Android NDK under Linux
« Reply #6 on: December 29, 2015, 09:06:49 pm »
I kind of assumed it would be something like that. You may try using "BINUTILSPREFIX=arm-android-" during FPC build and edit "fpc.cfg" adding something like (pay special attention to "-XP" flag):
Code: [Select]
#ifdef android
-XParm-android-
-Fl/opt/android-ndk/platforms/android-21/arch-arm/usr/lib
-FD/opt/android-ndk/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin
-OoFastMath
-CpARMv7a
-CfVFPv3_D16
-OpARMv7a
#endif

Note: even though some libraries are built for ARMv5, in my opinion, you should just target ARMv7a at minimum (you can use ARMv5 libs without any issues). In my own tests, any remaining ARMv6 devices (I've never seen an ARMv5 Android device) run either Android 2.3 Gingerbread, which is hostile to NDK apps, or even lower, which doesn't support NDK apps at all - so it is not worthwhile to even bother with it.

Edit: on PXL's wiki I've sort of documented how to prepare FPC for Android on Windows, but still hadn't got the chance to document the same on Linux, though I do have all the scripts. I haven't tried this on Arch Linux, however, might as well do it in a VM and see if I can get it to work. On Debian, the process is pretty straight-forward - install FPC seed, get FPC trunk sources, get NDK and build everything.
« Last Edit: December 29, 2015, 09:22:44 pm by ykot »

Ocye

  • Hero Member
  • *****
  • Posts: 518
    • Scrabble3D
Re: Android NDK under Linux
« Reply #7 on: December 29, 2015, 11:24:27 pm »
My mistake was another switch
Quote
#IFDEF FPC_CROSSCOMPILING
 -XP$FPCTARGET-
#ENDIF
(that was easy to exclude with "#IFNDEF android"; don't remember where it comes from)

And softlinks in /usr/local/bin to as and ld don't work. The path has to added to the environment vars and the softlinks must not bw there.

So yes, in the end it is straightforward. :-)
Many thanks for the head-ups. I'd have given up without.
Lazarus 1.7 (SVN) FPC 3.0.0

 

TinyPortal © 2005-2018