相关疑难解决方法(0)

使用 Clang 为 RISC-V 进行编译

我正在尝试使用 RISC-V 架构(版本 12.0.1)构建一个 hello world 程序Clang。我已经使用LLVM(版本 12.0.1)安装了它,设置如下:

cmake -G "Unix Makefiles" \
   -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra;libcxx;libcxxabi;libunwind;lldb;compiler-rt;lld;polly;debuginfo-tests" \
   -DCMAKE_BUILD_TYPE=Debug \
   -DLLVM_ENABLE_ASSERTIONS=On \
   ../llvm
Run Code Online (Sandbox Code Playgroud)

根据here,默认LLVM_TARGETS_TO_BUILDLLVM_ALL_TARGETS,其中包括RISC-V。

所以我尝试编译它,clang --target=riscv64 -march=rv64gc hello_world.c -o hello_world但收到错误:

hello_world.c:1:10: fatal error: 'stdio.h' file not found
#include <stdio.h>
         ^~~~~~~~~
1 error generated.
Run Code Online (Sandbox Code Playgroud)

同时,/opt/risv/我安装的riscv-gnu-toolchain, 位于我的路径中,我可以riscv64-unknown-linux-gnu-gcc hello_world.c -o hello_world毫无问题地运行。

我正在使用 kernel 的 Ubuntu 机器上尝试5.8.0-63-generic

知道如何解决这个问题并能够通过 Clang 编译 RISC-V 程序吗?

compilation llvm clang riscv

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

clang ×1

compilation ×1

llvm ×1

riscv ×1