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

clang compile error of hello.c #1

Open
winksaville opened this issue Oct 6, 2014 · 0 comments
Open

clang compile error of hello.c #1

winksaville opened this issue Oct 6, 2014 · 0 comments
Assignees

Comments

@winksaville
Copy link

I built clang and the gcc tools on my Ubuntu 13-04 linux box with a fork riscv-tools from yesterday.

The gcc tools compile and spike runs hello.c:

wink@ssi-primary:~/prgs/test$ cat hello.c

include <stdio.h>

int main() {
printf("Hello World\n");
}

wink@ssi-primary:~/prgs/test$ riscv-gcc -o hello hello.c

wink@ssi-primary:~/prgs/test$ spike pk hello
Hello World

But clang fails using the suggested command line from here:

wink@ssi-primary:~/prgs/test$ clang -target riscv -mriscv=RV64IAMFD -S hello.c -o hello.S
In file included from hello.c:1:
In file included from /usr/include/stdio.h:27:
In file included from /usr/include/features.h:341:
/usr/include/stdc-predef.h:30:10: fatal error: 'bits/predefs.h' file not found

include <bits/predefs.h>

     ^

1 error generated.

It seems the include paths aren't setup correctly, so I looked around and adding "-nostdinc -I/opt/riscv/riscv-elf/include -I/opt/riscv/lib/clang/3.3/include" worked, but I have a feeling there is a better and more correct way:

wink@ssi-primary:~/prgs/test$ clang -target riscv -mriscv=RV64IAMFD -nostdinc -I/opt/riscv/riscv-elf/include -I/opt/riscv/lib/clang/3.3/include -S hello.c -o hello.S

wink@ssi-primary:~/prgs/test$ cat hello.S
.file "hello.c"
.text
.globl main
.align 4
.type main,@function
main:
addi x14, x14, -32
sd x1, 24(x14)
sd x31, 16(x14)
sd x2, 8(x14)
add x2, x0, x14
lui x16, %hi(.L.str)
addi x18, x16, %lo(.L.str)
jal printf
sw x16, 4(x2)
addiw x16, x0, 0
add x14, x0, x2
ld x2, 8(x14)
ld x31, 16(x14)
ld x1, 24(x14)
addi x14, x14, 32
ret
.Ltmp3:
.size main, .Ltmp3-main

.type   .L.str,@object
.section    .rodata.str1.1,"aMS",@progbits,1

.L.str:
.asciz "Hello World\n"
.size .L.str, 13

.section    ".note.GNU-stack","",@progbits

wink@ssi-primary:~/prgs/test$ riscv-gcc -o hello.riscv hello.S

wink@ssi-primary:~/prgs/test$ spike pk hello.riscv
Hello World

Let me know if there is more information is needed.

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