Skip to content
Advertisement

native-image says “unknown type name ‘uint8_t'” during compilation

I’m getting this error:

$ 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'

I’m with 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

It seems that the problem is with this code in sys/resource.h:

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

This line with stdint.h doesn’t get included and that’s why uint8_t doesn’t get defined.

Advertisement

Answer

Possible solution

Please, consider trying to follow the instruction from 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 Cannot compile any C++ programs; error: unknown type name ‘uint8_t’

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.

The purpose of (the idea behind) renaming the include directory (from include to include.old) seems to be explained in the answer.

Additional references

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement