Why D needs a C compiler?
rempas
rempas at tutanota.com
Tue Aug 3 14:51:47 UTC 2021
On Tuesday, 3 August 2021 at 13:54:25 UTC, Paul Backus wrote:
> On Tuesday, 3 August 2021 at 12:59:49 UTC, rempas wrote:
>> To me big surprise, I tried to compile my program after
>> changing the "/bin/cc" link from "gcc" to "tcc" and I got an
>> error saying: `tcc: error: unsupported linker option
>> '--gc-sections'`.
>>
>> I haven't noticed that D needs a C compiler before. Why is
>> that and why the TinyC compiler (tcc) cannot be used and more
>> importantly, can we fix that?
>
> By default, the D compiler uses `cc` to invoke the linker. You
> can override this by setting the environment variable `CC` (on
> Posix) [1] or `LINKCMD64` (on Windows) [2].
>
> Alternatively, you can compiler your D modules separately with
> `dmd -c` and then invoke the linker directly to build the final
> executable (or have your build system do this).
>
> [1] https://dlang.org/dmd-linux.html#environment
> [2] https://dlang.org/dmd-windows.html#environment
Thanks for the info! Alright, I'm exporting the "CC" env variable
to "tcc" and still it will give me the error. I also tried to set
it to a linker (bot ld and lld) and I'm getting the following
errors:
```
ld.lld: error: unknown argument '-fuse-ld=ld'
ld.lld: error: unknown argument '-Wl,--gc-sections'
ld.lld: error: unknown emulation: 64
ld.lld: error: unable to find library -lrt
ld.lld: error: unable to find library -ldl
ld.lld: error: unable to find library -lpthread
ld.lld: error: unable to find library -lm
Error: /bin/ld.lld failed with status: 1
```
I used the "--help" option with ldc and it seems that there is an
option to set the linker ("--linker"), to pass options to the
linker ("-L") and an option to set the C compiler ("--gcc"). I'm
setting it up with the following command: `./bin/ldc2 test.d
--link-internally --linker=ld.lld -L="-L=/usr/lib64" -L"-lc"`.
However I'm still getting the HUGE following error message:
```
lld: error: undefined symbol: _Unwind_Resume
>>> referenced by curl.d
>>>
>>> curl.o:(_D4core8internal8lifetime__T10emplaceRefTS3std11concurrency__T4ListTSQBbQBa7MessageZQw4NodeTQBzTQBcZQCuFKQCmKQBpZv) in archive /usr/lib64/libphobos2-ldc.a
>>> referenced by object.d
>>>
>>> object.o:(_D6object9Throwable8toStringMxFMDFIAaZvZv) in
>>> archive /usr/lib64/libdruntime-ldc.a
>>> referenced by osthread.d
>>>
>>> osthread.o:(_D4core6thread8osthread6Thread5startMFNbZCQBoQBmQBiQBc) in archive /usr/lib64/libdruntime-ldc.a
>>> referenced 108 more times
lld: error: undefined symbol: _Unwind_DeleteException
>>> referenced by dwarfeh.d
>>> dwarfeh.o:(_d_eh_enter_catch) in archive
>>> /usr/lib64/libdruntime-ldc.a
>>> referenced by dwarfeh.d
>>> dwarfeh.o:(_d_eh_personality_common) in archive
>>> /usr/lib64/libdruntime-ldc.a
>>> referenced by dwarfeh.d
>>> dwarfeh.o:(_d_eh_personality_common) in archive
>>> /usr/lib64/libdruntime-ldc.a
lld: error: undefined symbol: _Unwind_RaiseException
>>> referenced by dwarfeh.d
>>> dwarfeh.o:(_d_throw_exception) in archive
>>> /usr/lib64/libdruntime-ldc.a
lld: error: undefined symbol: _Unwind_GetLanguageSpecificData
>>> referenced by dwarfeh.d
>>> dwarfeh.o:(_d_eh_personality_common) in archive
>>> /usr/lib64/libdruntime-ldc.a
lld: error: undefined symbol: _Unwind_GetRegionStart
>>> referenced by dwarfeh.d
>>> dwarfeh.o:(_d_eh_personality_common) in archive
>>> /usr/lib64/libdruntime-ldc.a
lld: error: undefined symbol: _Unwind_GetIPInfo
>>> referenced by dwarfeh.d
>>> dwarfeh.o:(_d_eh_personality_common) in archive
>>> /usr/lib64/libdruntime-ldc.a
lld: error: undefined symbol: _Unwind_SetGR
>>> referenced by dwarfeh.d
>>> dwarfeh.o:(_d_eh_personality_common) in archive
>>> /usr/lib64/libdruntime-ldc.a
>>> referenced by dwarfeh.d
>>> dwarfeh.o:(_d_eh_personality_common) in archive
>>> /usr/lib64/libdruntime-ldc.a
lld: error: undefined symbol: _Unwind_SetIP
>>> referenced by dwarfeh.d
>>> dwarfeh.o:(_d_eh_personality_common) in archive
>>> /usr/lib64/libdruntime-ldc.a
Error: linking with LLD failed
```
If I don't link the "libc", I will only get the error about the
"_Unwind_Resume" symbol but I will get other for "printf", "free"
etc. So yeah can anyone help?
More information about the Digitalmars-d
mailing list