0

I tried including secext.h winapi header in Kotlin/Native cinterop using Gradle:

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>

And IDE I use (IntelliJ Idea with the Kotlin plugin) does see the functions from secext.h and it does compile if I don't use any of them. When I try to use GetUserNameExA, though, this errors show up in :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

And I have literally no idea how to fix it.

TheChilliPL
  • 337
  • 1
  • 5
  • 14
  • Try to replace the `Secext.h` with `Security.h`, according to the [document](https://learn.microsoft.com/en-us/windows/win32/api/secext/nf-secext-getusernameexa#requirements). – Drake Wu May 04 '20 at 07:05
  • @DrakeWu-MSFT Security.h is included in secext_wrapper.h. I've also tried to put it into the headerFilter in secext.def but didn't work – TheChilliPL May 05 '20 at 07:28
  • Have you defined `WINAPI_FAMILY`, according to the definition in the header file `Secext.h`, the function `GetUserNameExA` is only available in Desktop Family or OneCore Family: `#if WINAPI_FAMILY_PARTITION (WINAPI_PARTITION_DESKTOP | WINAPI_PARTITION_SYSTEM)`. try to add `#define WINAPI_FAMILY WINAPI_FAMILY_DESKTOP_APP` before include the header. – Drake Wu May 05 '20 at 08:10
  • I did not. I'll check that when I can – TheChilliPL May 05 '20 at 10:25
  • It doesn't work, unfortunately – TheChilliPL May 05 '20 at 22:45

0 Answers0