www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Does anyone build for Android? Tons of link errors..

reply Fry <fry131313 gmail.com> writes:
I'm getting a ton of linker errors when building with LDC with 
the aarch64 release from here: 
https://github.com/ldc-developers/ldc/releases

```
Lib/Android/arm64-v8a/libphobos2-ldc.a(concurrency.o):(.data._D3std11concurrency12
_ModuleInfoZ+0x20): undefined reference to
`_D4core4sync9condition12__ModuleInfoZ'
Lib/Android/arm64-v8a/libphobos2-ldc.a(parallelism.o): In 
function `_D3std11parallelism13totalCPUsImplFNbNiNeZk':
parallelism.d:(.text._D3std11parallelism13totalCPUsImplFNbNiNeZk+0x20):
undefined reference to `CPU_COUNT'
Lib/Android/arm64-v8a/libphobos2-ldc.a(parallelism.o): In 
function `_D3std11parallelism8TaskPool6__ctorMFNeZCQBnQBmQBc':
parallelism.d:(.text._D3std11parallelism8TaskPool6__ctorMFNeZCQBnQBmQBc+0x64):
undefined reference to `CPU_COUNT'
Lib/Android/arm64-v8a/libphobos2-ldc.a(parallelism.o): In 
function `_D3std11parallelism8TaskPool6__ctorMFNemZCQBoQBnQBd':
parallelism.d:(.text._D3std11parallelism8TaskPool6__ctorMFNemZCQBoQBnQBd+0xc0):
undefined reference to `_D4core4sync9condition9Condition7__ClassZ'
parallelism.d:(.text._D3std11parallelism8TaskPool6__ctorMFNemZCQBoQBnQBd+0xc4):
undefined reference to `_D4core4sync9condition9Condition7__ClassZ'
parallelism.d:(.text._D3std11parallelism8TaskPool6__ctorMFNemZCQBoQBnQBd+0xd0):
undefined reference to `_D4core4sync9condition9Condition6__vtblZ'
parallelism.d:(.text._D3std11parallelism8TaskPool6__ctorMFNemZCQBoQBnQBd+0xd4):
undefined reference to `_D4core4sync9condition9Condition6__initZ'
parallelism.d:(.text._D3std11parallelism8TaskPool6__ctorMFNemZCQBoQBnQBd+0xd8):
undefined reference to `_D4core4sync9condition9Condition6__vtblZ'
parallelism.d:(.text._D3std11parallelism8TaskPool6__ctorMFNemZCQBoQBnQBd+0xdc):
undefined reference to `_D4core4sync9condition9Condition6__initZ'
parallelism.d:(.text._D3std11parallelism8TaskPool6__ctorMFNe
ZCQBoQBnQBd+0x108): undefined reference to
`_D4core4sync9condition9Condition6__ctorMFNbNfCQBsQBq5mutex5MutexZCQCmQCkQCiQCb'
parallelism.d:(.text._D3std11parallelism8TaskPool6__ctorMFNe
ZCQBoQBnQBd+0x134): undefined reference to
`_D4core4sync9condition9Condition6__ctorMFNbNfCQBsQBq5mutex5MutexZCQCmQCkQCiQCb'
Lib/Android/arm64-v8a/libphobos2-ldc.a(parallelism.o): In 
function 
`_D3std11parallelism__T27__lazilyInitializedConstantTykVki4294967295S_DQCqQCp13totalCPUsImplFNbNiNeZkZQDbFNaNbNdNiNfZyk':
parallelism.d:(.text._D3std11parallelism__T27__lazilyInitializedConstantTykVki4294967295S_DQCqQCp13totalCPUsImplFNbNiNeZkZQDbF
aNbNdNiNfZyk+0x60): undefined reference to `CPU_COUNT'
Lib/Android/arm64-v8a/libphobos2-ldc.a(parallelism.o): In 
function 
`_D3std11parallelism8taskPoolFNdNeZ9__lambda2FNfZCQBvQBu8TaskPool':
parallelism.d:(.text._D3std11parallelism8taskPoolFNdNeZ9__lambda2FNfZCQB
QBu8TaskPool+0xc0): undefined reference to `CPU_COUNT'
Lib/Android/arm64-v8a/libphobos2-ldc.a(parallelism.o): In 
function `_D3std11parallelism18defaultPoolThreadsFNdNeZk':
parallelism.d:(.text._D3std11parallelism18defaultPoolThreadsFNdNeZk+0x84):
undefined reference to `CPU_COUNT'
```

A lot of unresolved references to just CPU_COUNT. The confusing 
part is that it has undefined referenced to parts of in `core`, 
which I am linking the druntime as well. Is anyone able to build 
for android?
Feb 16 2022
next sibling parent reply "H. S. Teoh" <hsteoh quickfur.ath.cx> writes:
On Wed, Feb 16, 2022 at 08:40:02PM +0000, Fry via Digitalmars-d-learn wrote:
 I'm getting a ton of linker errors when building with LDC with the
 aarch64 release from here:
[...]
 Is anyone able to build for android?
I adapted the instructions from: https://wiki.dlang.org/Build_D_for_Android Works fine for me. Note that you will need a working installation of the Android NDK, and will need to build druntime/phobos specifically for cross-compilation, as detailed on that page. If you're planning to build APKs, you will need to install various Android utilities as well (dalvik-exchange, zipalign, apksigner, etc.). T -- All men are mortal. Socrates is mortal. Therefore all men are Socrates.
Feb 16 2022
parent Fry <fry131313 gmail.com> writes:
On Wednesday, 16 February 2022 at 22:50:09 UTC, H. S. Teoh wrote:
 On Wed, Feb 16, 2022 at 08:40:02PM +0000, Fry via 
 Digitalmars-d-learn wrote:
 I'm getting a ton of linker errors when building with LDC with 
 the aarch64 release from here:
[...]
 Is anyone able to build for android?
I adapted the instructions from: https://wiki.dlang.org/Build_D_for_Android Works fine for me. Note that you will need a working installation of the Android NDK, and will need to build druntime/phobos specifically for cross-compilation, as detailed on that page. If you're planning to build APKs, you will need to install various Android utilities as well (dalvik-exchange, zipalign, apksigner, etc.). T
I got that demo compiling, it seems this flag is causing it to not compile "-Wl,--no-undefined". But if it is undefined it shouldn't compile normally. There should be linker errors I'm expecting but if I take out that flag then I don't get any...
Feb 16 2022
prev sibling parent reply kinke <noone nowhere.com> writes:
On Wednesday, 16 February 2022 at 20:40:02 UTC, Fry wrote:
 A lot of unresolved references to just CPU_COUNT. The confusing 
 part is that it has undefined referenced to parts of in `core`, 
 which I am linking the druntime as well.
If you're linking manually, make sure that `-ldruntime-ldc` comes *after* `-lphobos2-ldc`, and that your druntime lib has been compiled for the appropriate arch. CPU_COUNT is a druntime symbol too.
Feb 16 2022
next sibling parent Fry <fry131313 gmail.com> writes:
On Thursday, 17 February 2022 at 01:17:51 UTC, kinke wrote:
 On Wednesday, 16 February 2022 at 20:40:02 UTC, Fry wrote:
 A lot of unresolved references to just CPU_COUNT. The 
 confusing part is that it has undefined referenced to parts of 
 in `core`, which I am linking the druntime as well.
If you're linking manually, make sure that `-ldruntime-ldc` comes *after* `-lphobos2-ldc`, and that your druntime lib has been compiled for the appropriate arch. CPU_COUNT is a druntime symbol too.
Yes I tried changing the order, it seems like I am getting all unresolved symbols for D. Including _d_assert, but only when I use the --no-undefined flag. I have no idea why it is spitting out so many unresolved references.
Feb 16 2022
prev sibling parent reply Fry <fry131313 gmail.com> writes:
I got it working, kind of. I just needed to use a different ndk 
version. There's a lot of problems with the NDK, the latest one 
doesn't appear to have the bfd linker anymore.

Does anyone know why the bfd linker is needed and why the gold 
linker doesn't work for the emulated TLS?
Feb 18 2022
parent kinke <noone nowhere.com> writes:
On Friday, 18 February 2022 at 16:28:56 UTC, Fry wrote:
 Does anyone know why the bfd linker is needed and why the gold 
 linker doesn't work for the emulated TLS?
It's required for LDC's custom TLS emulation for Android, see 1st point in https://wiki.dlang.org/Build_D_for_Android#Directions_for_future_work. lld supports custom linker scripts AFAIK, so that should get it to work as well (putting the two sections adjacent to each other). There's a runtime check making sure the executable has been linked as expected.
Feb 18 2022