How to compile D and C * .o files using GCC

I am trying to link D and C code using DMD compiler and GCC. I am trying to use the DMD compiler to compile the source into * .o files, using the GCC compiler to compile the C source into * .o files and using GCC to link to create the binary.

However, in the last step, give me linker errors by giving me some <undefined for architecture "errors"

dmd ../src/Main.d -I../src -c
gcc -c ../ext/clibs.c
gcc *.o -o Main
Undefined symbols for architecture x86_64:
  "_D10TypeInfo_k6__initZ", referenced from:
      _D11TypeInfo_xk6__initZ in Main.o
  "_D12TypeInfo_Aya6__initZ", referenced from:
      _D13TypeInfo_xAya6__initZ in Main.o
  "_D14TypeInfo_Const6__vtblZ", referenced from:
      _D11TypeInfo_xk6__initZ in Main.o
      _D13TypeInfo_xAya6__initZ in Main.o
  "_D3std5stdio12__ModuleInfoZ", referenced from:
      _D4Main12__ModuleInfoZ in Main.o
  "__d_arraybounds", referenced from:
      _D6object7__arrayZ in Main.o
      _D4core4stdc6stdint7__arrayZ in Main.o
      _D3std8typecons7__arrayZ in Main.o
      _D3std6traits7__arrayZ in Main.o
      _D3std9typetuple7__arrayZ in Main.o
  "__d_assert", referenced from:
      _D6object8__assertFiZv in Main.o
      _D4core4stdc6stdint8__assertFiZv in Main.o
      _D3std8typecons8__assertFiZv in Main.o
      _D3std6traits8__assertFiZv in Main.o
      _D3std9typetuple8__assertFiZv in Main.o
  "__d_run_main", referenced from:
      _main in Main.o
  "__d_unittest", referenced from:
      _D6object15__unittest_failFiZv in Main.o
      _D4core4stdc6stdint15__unittest_failFiZv in Main.o
      _D3std8typecons15__unittest_failFiZv in Main.o
      _D3std6traits15__unittest_failFiZv in Main.o
      _D3std9typetuple15__unittest_failFiZv in Main.o

I assume that the D * .o file refers to characters in the STD D library. How do I enable this when referenced?

+4
source share
1 answer

Answer. I came up with no need. Just use the DMD compiler for the last step

So instead

dmd ../src/Main.d -I../src -c
gcc -c ../ext/clibs.c
gcc *.o -o Main

Simply

dmd ../src/Main.d -I../src -c
gcc -c ../ext/clibs.c
dmd *.o

D-, C, extern (C)

mycfile.c

int myfunction() {
    return 3;
}

mycbridge.d

extern (C) int myfunction();

mycbridge.d D.

+2

All Articles