On Monday, 19 June 2017 at 10:24:29 UTC, Dan Walmsley wrote:
I have played around with the betterC flag and it looks
promising. I would also like to have use of classes, however as
soon as I try to use a class I get many link errors. see below:
It is my understanding that the DMD -betterC switch currently
only disables generating ModuleInfo. Walter's recent pull
request
(http://forum.dlang.org/post/oi9v2q$23ms$1...@digitalmars.com) makes
it do a little more.
It is also my understanding the -betterC is just an idea at the
moment, and what it should do has not yet been defined.
The undefined reference to `_d_dso_registry' comes from
removing the -betterC flag.
I understand these other symbols would be provided by object.d,
however I am unable to find an object.d that will compile on
LDC, and ideally a minimal implementation.
The most minimal implementation I'm aware of is this:
https://wiki.dlang.org/Minimal_semihosted_ARM_Cortex-M_%22Hello_World%22
If you're targeting STM32, you may also be interested in this:
https://github.com/JinShil/stm32f42_discovery_demo
I haven't tested either of those in quite some time, so I doubt
the will compile out of the box. But basically, what you need is
a minimal runtime implementation that implements the features of
D that your code is using, and unfortunately, some that your code
isn't using but is required by the compiler just to get a build.
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o: In function
`_D4main9TestClass3SumMFZi':
C:\dev\repos\STM32DBlinky\Blinky/main.d:9: undefined reference
to `_D9invariant12_d_invariantFC6ObjectZv'
C:\dev\repos\STM32DBlinky\Blinky/main.d:9: undefined reference
to `_d_assert_msg'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o: In function
`ldc.register_dso':
C:\dev\repos\STM32DBlinky\Blinky\main.d:(.text.ldc.register_dso+0x60):
undefined reference to `_d_dso_registry'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data.rel.ro._D4main9TestClass6__vtblZ[_D4main9TestClass6__vtblZ]+0x4):
undefined reference to `_D6object6Object8toStringMFZAya'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data.rel.ro._D4main9TestClass6__vtblZ[_D4main9TestClass6__vtblZ]+0x8):
undefined reference to `_D6object6Object6toHashMFNbNeZk'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data.rel.ro._D4main9TestClass6__vtblZ[_D4main9TestClass6__vtblZ]+0xc):
undefined reference to `_D6object6Object5opCmpMFC6ObjectZi'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data.rel.ro._D4main9TestClass6__vtblZ[_D4main9TestClass6__vtblZ]+0x10):
undefined reference to `_D6object6Object8opEqualsMFC6ObjectZb'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data._D4main9TestClass7__ClassZ[_D4main9TestClass7__ClassZ]+0x0):
undefined reference to `_D14TypeInfo_Class6__vtblZ'
C:\dev\repos\STM32DBlinky\Blinky\build\obj\main.o:(.data._D4main9TestClass7__ClassZ[_D4main9TestClass7__ClassZ]+0x28):
undefined reference to `_D6Object7__ClassZ'
`_d_assert_msg` and `_d_dso_registry` and those symbols with
`_d_invariant` in them look like missing druntime
implementations. You can see an old and unmaintained list of
such "runtime hooks" here: https://wiki.dlang.org/Runtime_Hooks.
Each compiler (DMD, LDC, and GDC) have their own druntime
implementation, unfortunately. LDC's implementation is here:
https://github.com/ldc-developers/druntime
I suspect the `.data.re.ro.*` symbols are the result of an error
in your linker script. That is you haven't added that `.data`
section to your linker script, so the symbols aren't being
populated. I'd have to see your linker script and source code
before I spend to much mental energy on it, though.
No compiler that I'm aware has a druntime implementation for the
ARM Cortex-M architecture, so the onus is on you to build
implement whatever features the toolchain is complaining about.
Mike