What is the reason that `typedef struct Foo Foo;` ...
# kotlin-native
j
What is the reason that
typedef struct Foo Foo;
winds up as
cnames.structs.Foo
whereas
typedef struct Foo { ... } Foo;
goes into
my.package.Foo
? I'm running into simple name collisions in
cnames.structs
which are causing compilation failures only on some native targets.
s
cnames.structs
is used to support forward declarations in Kotlin. More precisely, to support cases like "forward declaration (
typedef struct Foo Foo;
) gets into module A, and an actual declaration (
typedef struct Foo { ... } Foo;
) gets into module B". If both modules get into the compiler, then compiler magically resolves references to
cnames.structs.Foo
to
B.Foo
. Could you share a reproducer?
I assumed that you're talking about https://kotlinlang.slack.com/archives/C3SGXARS6/p1632238934261200, checked and created a ticket.
One possible workaround is add a "real" struct declaration to the def file. Something like this:
Copy code
---
typedef struct Foo {} Foo;
It will force
cinterop
to use
my.package.Foo
instead of
cnames.structs.Foo
. Does it work for you?
m
It does "magically" work in single target build, but does not work in HMPP after commonizer:
And magic does not work in tools like Dokka: https://github.com/Kotlin/dokka/issues/1992
j
Does it work for you?
Yes. Thanks! This is much better.