Skolson5903
06/22/2025, 7:25 PM#include "getrandom_wrapper.h"
ssize_t call_getrandom(void *buf, size_t buflen, unsigned int flags) {
return getrandom(buf, buflen, flags);
}
and the header is this:
#include <sys/random.h>
// Wrapper function to call getrandom()
ssize_t wrapper_getrandom(void *buf, size_t buflen, unsigned int flags);
This compiles and links fine using gcc and produces a small static library. The .def file looks like this:
headers = getrandom_wrapper.h
package = com.oldguy.crypto
linkerOpts = -L.,/usr/include/x86_64-linux-gnu/ -lgetrandom_wrapper
The gradle setup for linuxX64 cinterop is this:
compilations.getByName("main") {
val path = "${project.rootDir}/KmpCrypto/src/linuxMain/cinterop"
cinterops {
val myLibraryCinterop by creating {
defFile(project.file("$path/getrandom_wrapper.def"))
includeDirs(path, "/usr/include/x86_64-linux-gnu") // Ubuntu location of sys/random.h
}
}
}
At cinterop (gradle sync) time, this error pops:
/usr/include/x86_64-linux-gnu/sys/cdefs.h:153:34: error: function-like macro '__glibc_clang_prereq' is not defined
Has anyone else seen this and knows what causes it? This macro should be defined by the sys/features.h that gets pulled in by sys/random.h. The code snippet from features.h that isn't working looks like this:
/* Similarly for clang. Features added to GCC after version 4.2 may
or may not also be available in clang, and clang's definitions of
__GNUC(_MINOR)__ are fixed at 4 and 2 respectively. Not all such
features can be queried via __has_extension/__has_feature. */
#if defined __clang_major__ && defined __clang_minor__
# define __glibc_clang_prereq(maj, min) \
((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
#else
# define __glibc_clang_prereq(maj, min) 0
#endif
Thanks in advance for any ideas on how to diagnose/fix this.Adam S
06/23/2025, 10:41 AMrun_konan
tool.
https://github.com/JetBrains/kotlin/blob/v2.1.21/kotlin-native/HACKING.md#running-clang-the-same-way-kotlinnative-compiler-doesAdam S
06/23/2025, 10:43 AMSkolson5903
06/23/2025, 3:46 PMSkolson5903
06/26/2025, 9:13 AMrun_konan clang clang linux_x64 getrandom_wrapper.c -I /usr/include/x86_64-linux-gnu
I didn't see anywhere in the konan stuff where they have their own headers, so I pointed it at the standard ones. It still gets the same sort of error in features.h as the regular gcc:
In file included from getrandom_wrapper.c:1:
In file included from ./getrandom_wrapper.h:1:
In file included from /usr/include/x86_64-linux-gnu/sys/random.h:22:
In file included from /home/steve-olson/.konan/dependencies/x86_64-unknown-linux-gnu-gcc-8.3.0-glibc-2.19-kernel-4.9-2/x86_64-unknown-linux-gnu/sysroot/usr/include/features.h:378:
/usr/include/x86_64-linux-gnu/sys/cdefs.h:153:34: error: function-like macro '__glibc_clang_prereq' is not defined
#if __USE_FORTIFY_LEVEL == 3 && (__glibc_clang_prereq (9, 0) \
^
/usr/include/x86_64-linux-gnu/sys/cdefs.h:652:28: error: function-like macro '__glibc_clang_prereq' is not defined
#if __GNUC_PREREQ (4,8) || __glibc_clang_prereq (3,5)
^
2 errors generated.
I also got your custom build tasks working and tried them to see if the options they used made a difference. Same result.
I think I'm gonna file an issue and see what Jetbrains has to say. Thanks again for your help!Skolson5903
06/26/2025, 9:53 PM// Wrapper function to call getrandom()
long int wrapper_getrandom(void *buf, long unsigned int buflen, unsigned int flags);
And matching C code that looks like this:
#include "getrandom_wrapper.h"
#include <sys/random.h>
long int wrapper_getrandom(void *buf, long unsigned int buflen, unsigned int flags) {
return getrandom(buf, buflen, flags);
}
I recompiled the new library (with either gcc or clang, both work, konan_tools still gets the similar compile-time error) and attempted a sync. Cinterop STILL gets the error below, even though the only reference to system headers is in the compiled C code in the library. How is it figuring out what the includes are in the compiled C? Anyway I've punted at this point. I filed issue KT-78637, and am waiting to see if Jetbrains has a comment or something 🙂. The macro isn't defined in features.h (included by random.h) because the compiler major/minor/ versions in cinterop aren't up-to-date enough to get it defined.
Exception in thread "main" java.lang.Error: /usr/include/x86_64-linux-gnu/sys/cdefs.h:153:34: error: function-like macro '__glibc_clang_prereq' is not defined
at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.ensureNoCompileErrors(Utils.kt:292)
at org.jetbrains.kotlin.native.interop.indexer.UtilsKt.precompileHeaders(Utils.kt:435)
at org.jetbrains.kotlin.native.interop.gen.StubIrContext.<init>(StubIrDriver.kt:46)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLib(main.kt:347)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.processCLibSafe(main.kt:243)
at org.jetbrains.kotlin.native.interop.gen.jvm.MainKt.access$processCLibSafe(main.kt:1)
at org.jetbrains.kotlin.native.interop.gen.jvm.Interop.interop(main.kt:101)
at org.jetbrains.kotlin.cli.utilities.InteropCompilerKt.invokeInterop(InteropCompiler.kt:48)