www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Compiling to RiscV32

reply HuskyNator <HuskyNator protonmail.ch> writes:
Recently found out LDC supports cross-compiling to riscv, but 
while trying it out I can't seem to make it work. I am very 
likely missing something simple, as I haven't done something like 
this before. I've already been told it's likely something with 
linking, though I'm not sure how to set this up. (Nor even 
without imports & confined to 1 file)

Using a simple single '.d' file with no imports: `Error: cannot 
find program 'cc'`
With imports it's a longer issue:
```
E:\Code\D\Overig>ldc2 --mtriple=riscv32 --mcpu=generic-rv32 -c 
source/app.d
C:\Program Files\LDC 1.32\bin\..\import\std\stdio.d(49): Error: 
module `core.stdc.stddef` import `wchar_t` not found
C:\Program Files\LDC 1.32\bin\..\import\core\stdc\time.d(34): 
Error: undefined identifier `time_t`, did you mean function 
`time`?
... (many similar errors here)
C:\Program Files\LDC 1.32\bin\..\import\core\stdc\wchar_.d(175): 
Error: undefined identifier `wchar_t`, did you mean `dchar`?
```

Note, the command I'm using is: `ldc2 --mtriple=riscv32 
--mcpu=generic-rv32 -c source/app.d`

I've also wanted to look into dub's `--arch=riscv32` command, 
which should function given what I've read, though this just 
states it's not supported. (Even though I believe it should be 
using ldc for this?)

Apologies for naïvity here, I cant really find any examples or 
guidance.
Jul 05 2023
next sibling parent Dukc <ajieskola gmail.com> writes:
On Wednesday, 5 July 2023 at 17:00:53 UTC, HuskyNator wrote:
 Using a simple single '.d' file with no imports: `Error: cannot 
 find program 'cc'`
I haven't tried to compile to RiscV32, nor do know how it works. But this reads like LDC is not finding the C compiler it's trying to use. LDC uses a C compiler to call the linker, instead to calling the linker directly.
Jul 06 2023
prev sibling next sibling parent reply Kagamin <spam here.lot> writes:
You try to use C declarations, but they are specific to each C 
library, and different C libraries have different declarations, 
so headers can't decide which C library declarations to use. Try 
-mtriple=riscv32-unknown-linux
Jul 10 2023
parent reply HuskyNator <HuskyNator protonmail.ch> writes:
On Monday, 10 July 2023 at 14:09:47 UTC, Kagamin wrote:
 You try to use C declarations, but they are specific to each C 
 library, and different C libraries have different declarations, 
 so headers can't decide which C library declarations to use. 
 Try -mtriple=riscv32-unknown-linux
It seems to be somewhat transformative, this at least gets me different errors :). Where does this `-unknown-linux` postfix come from? `ldc2 -version`/`-help` did not mention it. ``` C:\Program Files\LDC 1.32\bin\..\import\core\stdc\stdio.d(1308): Error: function `core.stdc.stdio.vfprintf` `pragma(printf)` functions must be `extern(C) int vfprintf([parameters...], const(char)*, va_list)` C:\Program Files\LDC 1.32\bin\..\import\core\stdc\stdio.d(1311): Error: function `core.stdc.stdio.__isoc99_vfscanf` `pragma(scanf)` functions must be `extern(C) int __isoc99_vfscanf([parameters...], const(char)*, va_list)` et cetera ``` For reference, this code is purely: ``` module overig.app; import std.stdio: writeln, readln; int foo(int a, int b){ return a+b; } void main() { int a = foo(1,2); writeln(a); } ```
Jul 11 2023
next sibling parent Kagamin <spam here.lot> writes:
Probably bug in druntime, v-functions shouldn't have 
`pragma(printf)`, because they don't have arguments to check.
Jul 11 2023
prev sibling parent Kagamin <spam here.lot> writes:
Maybe the problem is with va_list, try to compile with 
-mtriple=riscv64-unknown-linux -mcpu=generic-rv64
Jul 12 2023
prev sibling parent Kagamin <spam here.lot> writes:
Worked for me on ldc 1.20 
https://forum.dlang.org/post/vuxuftogvszztdrrtbne forum.dlang.org
Jul 10 2023