本机图像在编译期间说 "unknown type name 'uint8_t'"

native-image says "unknown type name 'uint8_t'" during compilation

我收到此错误:

$ native-image -jar foo.jar bin/java-Objects.bin
...
[bin/java-Objects.bin:24855]    classlist:   1,143.29 ms,  0.96 GB
[bin/java-Objects.bin:24855]        (cap):   1,803.60 ms,  0.96 GB
[bin/java-Objects.bin:24855]        setup:   2,304.75 ms,  0.96 GB
Error: Error compiling query code (in /var/folders/vl/633jwjvn2jvbj9zfg1sgglhw0000gp/T/SVM-3396448792019069231/PosixDirectives.c). Compiler command '/usr/bin/cc -Wall -Werror -ObjC -o /var/folders/vl/633jwjvn2jvbj9zfg1sgglhw0000gp/T/SVM-3396448792019069231/PosixDirectives /var/folders/vl/633jwjvn2jvbj9zfg1sgglhw0000gp/T/SVM-3396448792019069231/PosixDirectives.c' output included error: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk/usr/include/sys/resource.h:202:2:
error: unknown type name 'uint8_t'

我和 Clang 在一起:

$ clang --version
Homebrew clang version 13.0.0
Target: x86_64-apple-darwin20.6.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

看来问题出在sys/resource.h中的这段代码:

#if __DARWIN_C_LEVEL >= __DARWIN_C_FULL
#include <stdint.h>
#endif /* __DARWIN_C_LEVEL >= __DARWIN_C_FULL */

带有 stdint.h 的这一行未包含在内,这就是 uint8_t 未定义的原因。

可能的解决方案

请考虑尝试遵循 quarkus/faq.adoc at main · quarkusio/quarkus 的说明:

1. Native compilation

Native executable fails on macOS with error: unknown type name 'uint8_t'

Your macOS has the wrong *.h files compared to the OS and no gcc compilation will work. This can happen when you migrate from versions of the OS. See

The solution is to

  • sudo mv /usr/local/include /usr/local/include.old
  • Reinstall XCode for good measure
  • (optional?) brew install llvm
  • generally reinstall your brew dependencies with native compilation

The executable should work now.

重命名 include 目录(从 includeinclude.old)的目的(背后的想法)似乎在 中有解释。

其他参考文献

  • 相关问题。可能包含一些可能的解决方案。 .