When I'm trying to use a function from cinterop, c...
# kotlin-native
c
When I'm trying to use a function from cinterop, clang++ throws a weird error:
Copy code
e: C:\Users\Chilli\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1/bin/clang++ invocation reported errors

The C:\Users\Chilli\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1/bin/clang++ command returned non-zero exit code: 1.
output:
C:\Users\Chilli\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1\bin\ld: C:\Users\Chilli\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1\bin\ld: DWARF error: mangled line number section (bad file number)
C:\Users\Chilli\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1\bin\ld: DWARF error: mangled line number section (bad file number)
...
C:\Users\Chilli\.konan\dependencies\msys2-mingw-w64-x86_64-clang-llvm-lld-compiler_rt-8.0.1\bin\ld: DWARF error: mangled line number section (bad file number)
C:\Users\Chilli\AppData\Local\Temp\konan_temp2904216670241181048\result.o:out:(.text+0x7e4d1): undefined reference to `GetUserNameExA'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)

> Task :linkDebugSharedWindows FAILED

Execution failed for task ':linkDebugSharedWindows'.
> Compilation finished with errors
Just if the reference weren't there, but IntelliJ does see this function. It's a function from secext.h that I'm importing using secext.def:
Copy code
headers = secext_wrapper.h
headerFilter = secext.h
package = me.[...].cinterop.secext

linkerOpts.mingw = -lpsapi
and secext_wrapper.h:
Copy code
#pragma once
#include <windows.h>
#define SECURITY_WIN32
#include <security.h>
Any idea why doesn't it work?
k
it looks like the library you're trying to interop with was built with an incompatible toolchain
c
secext_wrapper.h
is my own header, compiled (successfully) with cinterop in Gradle and
secext.h
is a header from Windows SDK, included in
security.h
k
in that case i'm unsure, but the linker doesn't like one of the libraries
c
What do I do then? I can't compile it myself cause it's a part of winapi, after all
a
Hello, @Chilli! Can you clarify a bit, what’s the reason behind adding
secext.h
to the header filter? If I understood you correctly, without this line your interop was fine.
c
If I don't do it and just add a declaration of a secext function in my header, it doesn't work either
It only works if I'm not using any of the methods anywhere in my code. If I am, it doesn't compile
a
Okay, so you’re getting .def like that working:
Copy code
headers = secext_wrapper.h
package = me.[...].cinterop.secext

linkerOpts.mingw = -lpsapi
With some Kotlin stubs including the
GetUserNameExA
function, but cannot compile it correctly? Probably, one should add some other linker options, something about secur32.
c
Yeah, it crashes on linking
a
Hello again, @Chilli! I just noticed your problem can be still relevant, what’s the status? Have you tried to extend the linker options list with a
-lsecur32
?
c
Still not solved. I didn't try
-lsecur32
thing yet, I'll check it out once I can
@Artyom Degtyarev [JB] Wow, that actually worked! I can't believe it was so simple! What does that
-lsecur32
option do?
k
links that library