www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.ldc - Cross-compile with LDC

reply Jacob Carlborg <doob me.com> writes:
If I want to cross-compile with LDC, the host being OS X and the target 
being Linux 64bit. What would be the easiest way, can I use the tools 
from ELLCC [1]?

Can I specify the linker in LDC or do I need to separately link?

[1] http://ellcc.org

-- 
/Jacob Carlborg
Feb 18 2016
next sibling parent reply Dan Olson <gorox concast.net> writes:
On Thursday, 18 February 2016 at 21:11:52 UTC, Jacob Carlborg 
wrote:
 If I want to cross-compile with LDC, the host being OS X and 
 the target being Linux 64bit. What would be the easiest way, 
 can I use the tools from ELLCC [1]?

 Can I specify the linker in LDC or do I need to separately link?

 [1] http://ellcc.org
Search back and Kai wrote a post on cross compiling to arm64. I cross compile to iOS but using the iPhone sdk is a different process than what I think you want. Dan
Feb 18 2016
parent reply Kai Nacke <kai redstar.de> writes:
On Friday, 19 February 2016 at 01:11:52 UTC, Dan Olson wrote:
 On Thursday, 18 February 2016 at 21:11:52 UTC, Jacob Carlborg 
 wrote:
 If I want to cross-compile with LDC, the host being OS X and 
 the target being Linux 64bit. What would be the easiest way, 
 can I use the tools from ELLCC [1]?

 Can I specify the linker in LDC or do I need to separately 
 link?

 [1] http://ellcc.org
Search back and Kai wrote a post on cross compiling to arm64. I cross compile to iOS but using the iPhone sdk is a different process than what I think you want. Dan
For reference: http://forum.dlang.org/post/fhwvxatxezkafnalwhqr forum.dlang.org Regards, Kai
Feb 20 2016
parent Jacob Carlborg <doob me.com> writes:
On 2016-02-20 19:08, Kai Nacke wrote:

 For reference:
 http://forum.dlang.org/post/fhwvxatxezkafnalwhqr forum.dlang.org

 Regards,
 Kai
Thanks. -- /Jacob Carlborg
Feb 21 2016
prev sibling parent reply Joakim <dlang joakim.fea.st> writes:
On Thursday, 18 February 2016 at 21:11:52 UTC, Jacob Carlborg 
wrote:
 If I want to cross-compile with LDC, the host being OS X and 
 the target being Linux 64bit. What would be the easiest way, 
 can I use the tools from ELLCC [1]?

 Can I specify the linker in LDC or do I need to separately link?

 [1] http://ellcc.org
As in linux/AArch64? There are two steps to cross-compiling with ldc: 1. Cross-compile druntime and phobos for the OS/arch combo you want. This is easy to do using the cmake build scripts that come with the ldc source, assuming ldc, druntime and phobos already support the platform you want. Simply set D_FLAGS to the llvm triple and any other specific flags you need, as I do for Android/ARM (https://gist.github.com/joakim-noah/63693ead3aa62216e1d9#file-ldc android_arm-L3131), and set CC to a C cross-compiler for your target platform (export CC=/home/jacob/elcc-linux-aarch64/bin/clang), as there are a few C files and one asm file that druntime and phobos require. You may also need to set RT_CFLAGS, depending on the C compiler for your platform (can be seen in the link below). 2. Specify a linker for your OS/arch when cross-compiling with ldc. If you have a C compiler already configured to use that linker, as elcc might provide, all that requires is setting CC to that C compiler before running ldc, as shown above. Otherwise, you can cross-compile to object files using ldc and the -c flag, then run your linker by hand, as I do with the Android NDK (https://gist.github.com/joakim-noah/63693ead3aa62216e1d9#file-ldc_android_arm-L3164).
Feb 19 2016
parent reply Jacob Carlborg <doob me.com> writes:
On 2016-02-19 09:51, Joakim wrote:

 As in linux/AArch64?  There are two steps to cross-compiling with ldc:
No, as in Linux x86_64.
 1. Cross-compile druntime and phobos for the OS/arch combo you want.
 This is easy to do using the cmake build scripts that come with the ldc
 source, assuming ldc, druntime and phobos already support the platform
 you want.  Simply set D_FLAGS to the llvm triple and any other specific
 flags you need, as I do for Android/ARM
 (https://gist.github.com/joakim-noah/63693ead3aa62216e1d9#file-ldc_android_arm-L3131),
 and set CC to a C cross-compiler for your target platform (export
 CC=/home/jacob/elcc-linux-aarch64/bin/clang), as there are a few C files
 and one asm file that druntime and phobos require.  You may also need to
 set RT_CFLAGS, depending on the C compiler for your platform (can be
 seen in the link below).
Since this is for Linux x86_64, could I just use the pre-compiled libraries from the Linux release? What is RT_CFLAGS for?
 2. Specify a linker for your OS/arch when cross-compiling with ldc.  If
 you have a C compiler already configured to use that linker, as elcc
 might provide, all that requires is setting CC to that C compiler before
 running ldc, as shown above.  Otherwise, you can cross-compile to object
 files using ldc and the -c flag, then run your linker by hand, as I do
 with the Android NDK
 (https://gist.github.com/joakim-noah/63693ead3aa62216e1d9#file-ldc_android_arm-L3164).
That seems pretty simple. -- /Jacob Carlborg
Feb 19 2016
next sibling parent kinke <noone nowhere.com> writes:
On Friday, 19 February 2016 at 12:06:15 UTC, Jacob Carlborg wrote:
 What is RT_CFLAGS for?
They are the compile flags for the C parts of druntime/Phobos (zlib etc.).
Feb 19 2016
prev sibling parent reply Joakim <dlang joakim.fea.st> writes:
On Friday, 19 February 2016 at 12:06:15 UTC, Jacob Carlborg wrote:
 On 2016-02-19 09:51, Joakim wrote:
 1. Cross-compile druntime and phobos for the OS/arch combo you 
 want.
 This is easy to do using the cmake build scripts that come 
 with the ldc
 source, assuming ldc, druntime and phobos already support the 
 platform
 you want.  Simply set D_FLAGS to the llvm triple and any other 
 specific
 flags you need, as I do for Android/ARM
 (https://gist.github.com/joakim-noah/63693ead3aa62216e1d9#file-ldc_android_arm-L3131),
 and set CC to a C cross-compiler for your target platform 
 (export
 CC=/home/jacob/elcc-linux-aarch64/bin/clang), as there are a 
 few C files
 and one asm file that druntime and phobos require.  You may 
 also need to
 set RT_CFLAGS, depending on the C compiler for your platform 
 (can be
 seen in the link below).
Since this is for Linux x86_64, could I just use the pre-compiled libraries from the Linux release?
Probably? Ldc "should" produce the exact same output on another OS and be able to use a standard library compiled elsewhere, provided you use the same version of ldc and llvm. I haven't actually tried it, to see if that theory works out in practice. ;)
 What is RT_CFLAGS for?
As kinke says, those are the flags passed to your C compiler when building the C parts of druntime and phobos. An example can be seen in my second link above, when invoking the clang Android/ARM cross-compiler from the Android NDK.
Feb 19 2016
parent Jacob Carlborg <doob me.com> writes:
On 2016-02-19 18:14, Joakim wrote:

 Probably?  Ldc "should" produce the exact same output on another OS and
 be able to use a standard library compiled elsewhere, provided you use
 the same version of ldc and llvm.  I haven't actually tried it, to see
 if that theory works out in practice. ;)
Thanks, I'll give it a try.
 As kinke says, those are the flags passed to your C compiler when
 building the C parts of druntime and phobos.  An example can be seen in
 my second link above, when invoking the clang Android/ARM cross-compiler
 from the Android NDK.
Make sense now when I read the whole name :). Thanks. -- /Jacob Carlborg
Feb 20 2016