Trying to call some C code using Extern(C) but got unexpected linker error

Xiaochao Yan leon_whbc at yahoo.com
Sat Jun 8 02:22:00 UTC 2024


Hi, I am new to D and is experimenting with game development 
using D and C.

I had some problem when trying to recreate the
https://dlang.org/spec/importc.html

Environment:
Windows 11
gcc.exe (i686-posix-dwarf-rev0, Built by MinGW-W64 project) 8.1.0

Error Message:
```
lld-link: error: undefined symbol: _D4test4mainFZ12printMessageUZv
>>> referenced by test.obj:(_Dmain)

```

```
// .c file
#include <stdio.h>

void printMessage() {
     printf("Hello from C!\n");
}
```

```
// .d file
import std.stdio;
import std.conv;
import test;

void main() {

     writeln("Hello, World!");
     extern (C) void printMessage();
     printMessage();
}
```
Thanks in advance!


More information about the Digitalmars-d-learn mailing list