Undefined Reference calling D from C using static linking
data pulverizer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Thu Mar 23 03:49:37 PDT 2017
On Thursday, 23 March 2017 at 10:16:22 UTC, Nicholas Wilson wrote:
>
> It has to do with module references to druntime stuff. You can
> either try adding a
>
> pragma(LDC_no_module_info); //I think it is spelled correctly.
>
> or you can use ldc to link and it will link druntime
>
> gcc ccode.c -c
> ldc2 dcode.d code.o
>
> I don't know how well that will work.
Many thanks, I tried:
```
pragma(LDC_no_moduleinfo) //
https://wiki.dlang.org/LDC-specific_language_changes#LDC_no_moduleinfo
```
which worked, your method of doing the final compilation using
ldc2 (or dmd) also works :-)
Is there a dmd equivalent for `pragma(LDC_no_module_info);`?
Attempting the final compilation `gcc -o output ccode.o dcode.o`
after the second stage compilation `dmd -c dcode.d` gives an
error:
```
dcode.o: In function `_D5dcode7__arrayZ':
dcode.d:(.text._D5dcode7__arrayZ+0x23): undefined reference to
`_d_arraybounds'
dcode.o: In function `_D5dcode8__assertFiZv':
dcode.d:(.text._D5dcode8__assertFiZv+0x23): undefined reference
to `_d_assert'
dcode.o: In function `_D5dcode15__unittest_failFiZv':
dcode.d:(.text._D5dcode15__unittest_failFiZv+0x23): undefined
reference to `_d_unittest'
dcode.o:(.text.d_dso_init[.data.d_dso_rec]+0x22): undefined
reference to `_d_dso_registry'
collect2: error: ld returned 1 exit status
```
```
dmd --version
DMD64 D Compiler v2.073.2
Copyright (c) 1999-2016 by Digital Mars written by Walter Bright
```
More information about the Digitalmars-d-learn
mailing list