Fail to set LD_LIBRARY_PATH then cross build for ARM

Joakim via digitalmars-d-ldc digitalmars-d-ldc at puremagic.com
Wed Aug 2 16:51:55 PDT 2017


On Wednesday, 2 August 2017 at 21:39:00 UTC, Oleg B wrote:
> On Wednesday, 2 August 2017 at 03:28:48 UTC, Joakim wrote:
> Thank you! I found -L/usr/lib64 switch in /etc/ldc2.conf. In 
> .ldc/ldc2.conf I configure build for arm and it's work!

Great!

> Question about it: why '.ldc'? Why not '.config/' dir?

No idea, maybe that should be updated.

>> See this previous post for an example:
>>
>> http://forum.dlang.org/post/skdqeursuheqdsermmwh@forum.dlang.org
>
> Cool! But I don't understand how it use through dub. Dub don't 
> know about any arch expect x86(_64). If add dflags "-march=arm" 
> or something like this in dub.sdl it applies only for building 
> package, not for dependencies. Building without dub is some 
> painful for me and it's not useful to change .ldc/ldc2.conf 
> when need arm and when need x86... Maybe I do something wrong?

So you want to compile dub packages for ARM using a ldc 
cross-compiler on x86?  While dub works fine natively on ARM, I 
don't think it supports switching back and forth between natively 
compiling and cross-compiling yet.  You may be able to configure 
it another way by writing a config file at ~/.dub/settings.json, 
like this:
{
     "defaultCompiler" : "/home/oleg/ldc-arm-cross/bin/ldc2"
}

This would need to be an ldc cross-compiler with the armhf triple 
enabled by default, ie you'd have to compile llvm with that 
default triple.  Then, when you want to compile for x86, simply 
change the defaultCompiler or move the settings.json.

I think this should trick dub into cross-compiling everything for 
ARM, but I've never tried it.  The alternative might be patching 
dub so that you could use the same ldc build for both native and 
cross-compilation, rather than swapping out two different 
compilers like this.

>> We're working on making it much simpler to cross-compile the 
>> stdlib for the next ldc 1.4 beta, see kinke's latest patch 
>> here:
>>
>> https://github.com/ldc-developers/ldc/pull/2253
>
> I'm looking forward to full cross-building. It's plained? Or 
> always be need external cross-linker?

There has been some work on integrating lld, the llvm linker, but 
I don't know if we'll ever ship it, so maybe it'll always require 
getting that.

>> I'm not sure how well your approach will work, as the ldc 1.4 
>> stdlib may not work with ldc 1.3.  I'll be submitting a PR 
>> soon that should make it even easier, so you may want to wait 
>> for the next 1.4 beta instead.
>
> Can't wait 1.4 beta, business does not wait =)

In that case, you can follow the instructions here for 
Android/ARM, but modify them for linux/armhf to create your own 
cross-compiler:

https://wiki.dlang.org/Build_LDC_for_Android

Don't use that llvm patch for Android, but use the llvm default 
triple you need for your arm board.  You will have to change the 
C flags from the ldc patch for your platform, but don't need the 
rest of it.  You don't have to checkout the 1.3 branch, if you 
want 1.4, and no need for the Phobos patch.  If you want to build 
the test runners, no need for the druntime test runner patch, 
though one test in std.random will likely fail for you.

If you want to make it easier to use the ldc toolchain for 
cross-compiling, you may want to engage kinke or one of the other 
ldc devs in some consulting work, as I believe they do similar 
consulting work for Weka.io.


More information about the digitalmars-d-ldc mailing list