Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello.c compilation error #39

Open
nitish2112 opened this issue Nov 10, 2016 · 1 comment
Open

hello.c compilation error #39

nitish2112 opened this issue Nov 10, 2016 · 1 comment

Comments

@nitish2112
Copy link

nitish2112 commented Nov 10, 2016

I am having this issue while compiling hello.c. I tried the solution mentioned in the other issue as well. Please see the compilation results below:

PS: I noticed that I did not have riscv-elf folder in my /opt/riscv folder which has all the the standard libraries. What is wrong with the installation. I followed the steps here: https://riscv.org/software-tools/low-level-virtual-machine-llvm/

Compilation Results:
% clang -target riscv64 -mriscv=RV64IAMFD -S hello.c -o hello.S

gives:
In file included from hello.c:1:
In file included from /usr/include/stdio.h:27:
/usr/include/features.h:367:12: fatal error: 'sys/cdefs.h' file not found
#include
^
1 error generated.

% clang -target riscv -mriscv=RV64IAMFD -nostdinc -I/opt/riscv/riscv-elf/include -I/opt/riscv/lib/clang/3.9.0/include -S hello.c -o hello.S

gives:
hello.c:1:10: fatal error: 'stdio.h' file not found
#include
^
1 error generated.

and
% clang -target riscv64 -mriscv=RV64IAMFD -nostdinc -I/opt/riscv/riscv-elf/include -I/opt/riscv/lib/clang/3.9.0/include -S hello.c -o hello.S

gives:
hello.c:1:10: fatal error: 'stdio.h' file not found
#include
^
1 error generated.

@hirooih
Copy link

hirooih commented Apr 4, 2017

I know this project is not active, but I'd like to share a result of my experiment.

The option --sysroot=XXX changes the system root (normally /usr), and ${target}-clang let clang look for ${target}-as/ld/gcc.

See the following links for more details;
http://clang.llvm.org/docs/CrossCompilation.html
http://clang-developers.42468.n3.nabble.com/ccc-gcc-name-equivalent-to-call-as-and-ld-directly-td3076391.html

Thus if you installed riscv-tools under /opt/riscv, you can compile files only by clang as follows.

$ RISCV=/opt/riscv
$ mkdir $RISCV/r64
$ ln -s ../riscv64-unknown-elf $RISCV/r64/usr
$ ln -s clang $RISCV/bin/riscv64-unknown-elf-clang

Now I can do;

$ riscv64-unknown-elf-clang --sysroot=/opt/riscv/r64 hello.c
$ spike pk a.out
Hello world!
$ 

On the other hand, clang in this repository looks for risc-unknown-elf-* instead of risc32-unknown-elf-*
for RV32I.

Here is my fixes for this issue.

riscv-clang.patch.txt
riscv-llvm.patch.txt

With this fix now I can run dhrystone on my Sifive Hifive board.
Note that you need a symbolic link for this.

$ cd .../freedom-e-sdk/toolchain/bin
$ ln -s $RISCV/bin/clang riscv32-unknown-elf-clang

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants