我尝试使用 Gradle 在 Kotlin/Native cinterop 中包含 secext.h winapi 标头:
build.gradle
:
// ...
kotlin {
mingwX64("windows") {
compilations.main {
cinterops {
secext {
packageName 'me.[...].cinterop.secext'
includeDirs.allHeaders("src/nativeInterop/cinterop")
}
}
}
// ...
}
// ...
}
// ...
src/nativeInterop/cinterop/secext.def
:
headers = secext_wrapper.h
headerFilter = secext.h
package = me.[...].cinterop.secext
src/nativeInterop/cinterop/secext_wrapper.h
:
#pragma once
#include <windows.h>
#define SECURITY_WIN32
#include <security.h>
我使用的 IDE(带有 Kotlin 插件的 IntelliJ Idea)确实看到了 secext.h 中的函数,如果我不使用它们中的任何一个,它就会编译。但是,当我尝试使用GetUserNameExA
时,此错误显示在:linkDebugSharedWindc
:
> Task :linkDebugSharedWindows
Produced library API in gpio4k_api.h
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)
[many identical lines here]
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_temp8580678556601557020\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
我真的不知道如何解决它。