ImportC in a Dub project

Carsten Schlote carsten.schlote at gmx.net
Fri Oct 28 17:45:59 UTC 2022


Hi,

I created a Dub project containing two files: app.d and 
zstd_binding.c

```
$ cat source/zstd_binding.c

#include <zstd.h>
#include <zstd_errors.h>

#include <stdio.h>

void relatedCode(void)
{
	printf("Hallo! This is some output from C code!\n");
}
```
and
```
$ cat source/app.d
import std.conv;
import std.stdio;

import zstd_binding;

void main()
{
	auto versionNr = ZSTD_versionNumber();
	auto versionStr = ZSTD_versionString();
	writefln("Version Info: Numeric %d String %s", versionNr, 
versionStr.to!string);

	/** more code stripped */

	relatedCode(); // The linker can't find it....
}

```

Accessing ZSTD works perfect. For linking you must give "-lzstd". 
So far, so good. The problem started, when I try to access the 
```relatedCode()``` C function. There is simply no code generated 
for this C function. I need to compile the C separately into an 
object file and pass it as extra linker argument.

I expected that ImportC also allows to import C functions and 
creates the required code on the fly.

Is this a bug? What's wrong?




More information about the Digitalmars-d-learn mailing list