LDC / BetterC / _d_run_main
Mike Franklin
slavo5150 at yahoo.com
Sat Mar 10 07:54:33 UTC 2018
On Saturday, 10 March 2018 at 02:25:38 UTC, Richard wrote:
> Hi,
> I've been trying to see if I can get an mbed project to work
> with Dlang
> basically compiling D code for use on a Cortex-M Proccessor
You might be interested in the following, if you're not already
aware:
* https://github.com/JinShil/stm32f42_discovery_demo
* https://bitbucket.org/timosi/minlibd
The STM32 demo only supports GDC right now, but I'll be updating
it to support LDC when 2.079.0 lands there. 2.079.0 removes some
coupling of the compiler to the runtime, so I should be able to
avoid the following bugs:
https://github.com/ldc-developers/ldc/issues/created_by/JinShil
> so I tried this instead
> ```
> extern (C) int _d_run_main(int argc, char **argv, void*
> mainFunc) {
> MainFuncType mFunc = cast(MainFuncType) mainFunc;
> return mFunc(null);
> }
> ```
>
> but nope that didn't seem to work ether, compiles okay but the
> code in main() (D space) isn't called
> I'd imagine this should be a simple thing, anyone got any ideas?
The following worked fine for me on my x64 Linux desktop with LDC
version 1.8.0 (DMD v2.078.3, LLVM 5.0.1)
``` main.d
import core.stdc.stdio;
private alias extern(C) int function(char[][] args) MainFuncType;
extern (C) int _d_run_main(int argc, char **argv, void* mainFunc)
{
MainFuncType mFunc = cast(MainFuncType) mainFunc;
return mFunc(null);
}
void main()
{
printf("Hello, World!\n");
}
```
Compile with: ldc2 -defaultlib= -debuglib= -betterC main.d
Mike
More information about the Digitalmars-d-learn
mailing list