importC is not working in GDC?

felixfxu felixfxu at gmail.com
Fri Oct 10 14:10:53 UTC 2025


On Friday, 10 October 2025 at 10:52:44 UTC, Iain Buclaw wrote:
> Therefore, the D module needs to be told where to find the 
> source files, with `-I source`
>
> Mind that C sources need to be preprocessed before handing them 
> over to the D compilation unit.
> https://gcc.gnu.org/onlinedocs/gdc/ImportC.html

thanks, yes, `-I source` worked in my case. I have a sub folder 
of `source` which caused the problem.

Then I removed sub folder of `source` and continue the test.

I tried to manually call the pre-processor:

```sh
gcc -E file2.c > file2.i
gdc main.d file2.i -o main
```
It worked (no `#include` yet) so I assume the command is correct.

Then I add `#include <stdio.h>` in file2.c and run the commands 
again:
```c
//file2.c
#include <stdio.h>
void test()
{
}
```
```d
//main.d
import file2;
void main()
{
	file2.test();
}
```

```sh
gcc -E file2.c > file2.i
gdc main.d file2.i -o main
```
I got this error:

```
gdc main.d file2.i -o main
/usr/include/stdio.h:264:44: error: found ‘__filename’ when 
expecting ‘,’
   264 | extern FILE *fopen (const char *__restrict __filename,
       |                                            ^
/usr/include/stdio.h:264:54: error: no type-specifier for 
parameter
   264 | extern FILE *fopen (const char *__restrict __filename,
```
maybe it does not recognize `__restrict `?

I tried both gdc (version 13) and gdc-14, same error.

Anything wrong with the commands that I have used?



More information about the D.gnu mailing list