【问题标题】:native-image says "unknown type name 'uint8_t'" during compilationnative-image 在编译期间显示“未知类型名称'uint8_t'”
【发布时间】:2022-02-06 20:57:05
【问题描述】:

我收到此错误:

$ 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 的原因。

【问题讨论】:

  • 你知道'__DARWIN_C_LEVEL >= __DARWIN_C_FULL'是否为真吗?
  • 您能否分享一个在编译时出现此错误的简单示例?
  • @RobbingDaHood 显然,这不是真的。这就是为什么没有加载stdint.h :(
  • 如果你粗略地删除条件,然后导入它怎么办..?
  • @RobbingDaHood 这是我的代码:Objects.java

标签: java graalvm graalvm-native-image


【解决方案1】:

可能的解决方案

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

1。本机编译

本机可执行文件在 macOS 上失败,error: unknown type name 'uint8_t'

与操作系统相比,您的 macOS 有错误的 *.h 文件,并且 gcc 编译将不起作用。当您从操作系统版本迁移时,可能会发生这种情况。见Cannot compile any C++ programs; error: unknown type name 'uint8_t'

解决办法是

  • sudo mv /usr/local/include /usr/local/include.old
  • 重新安装 XCode 以取得好成绩
  • (可选?)brew install llvm
  • 通常使用本机编译重新安装您的 brew 依赖项

可执行文件现在应该可以工作了。

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

其他参考

【讨论】:

    猜你喜欢
    • 2018-06-10
    • 1970-01-01
    • 1970-01-01
    • 2014-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-19
    • 1970-01-01
    相关资源
    最近更新 更多