Thread overview
ImportC: unresolved external symbol
Jun 14, 2022
ryuukk_
Jun 14, 2022
Mike Parker
Jun 14, 2022
ryuukk_
June 14, 2022

Hello

Tried to give ImportC a try to finally get rid of gluecode in one of my project, but this simple test gives me a compile error:

nk.c

int test(void)
{
    return 1;
}

app.d

import std.stdio;
import nk = nk;

void main()
{
    if (nk.test() != 0)
    {
	    writeln("test");
    }
}

nk.obj : error LNK2019: unresolved external symbol test referenced in function _Dmain

Am i missing something important? (that is a dub project, created with: dub init)

DMD: v2.100.0-dirty

June 14, 2022

On Tuesday, 14 June 2022 at 14:32:50 UTC, ryuukk_ wrote:

>
nk.obj : error LNK2019: unresolved external symbol test referenced in function _Dmain

Am i missing something important? (that is a dub project, created with: dub init)

DMD: v2.100.0-dirty

This works from the command line:

dmd -m64 app.d nk.c

It's possible dub isn't passing the C file to the compiler. Assuming everything's configured properly (e.g., both files are in the same source directory, or the paths are properly set if they aren't), you should do a verbose build and see what the compiler command line looks like.

June 14, 2022

On Tuesday, 14 June 2022 at 14:38:17 UTC, Mike Parker wrote:

>

On Tuesday, 14 June 2022 at 14:32:50 UTC, ryuukk_ wrote:

>
nk.obj : error LNK2019: unresolved external symbol test referenced in function _Dmain

Am i missing something important? (that is a dub project, created with: dub init)

DMD: v2.100.0-dirty

This works from the command line:

dmd -m64 app.d nk.c

It's possible dub isn't passing the C file to the compiler.

That was the issue!

Adding the file manually in the dub.json solved it!

    "sourceFiles": [ "source/nk.c" ]

That should be easy to fix, i'll fill a PR

Thanks