I am currently using clang11 on ubuntu to compile any c/c++ code and it works fine but when I tried to compile any code (including any standard library) to assembly code for any specific target like x86_64
(even I have x86_64) riscv
with giving a flag that --target=x86_64
or --target=riscv32
I got errors for any standard library that I included in my code. A simple example:
// ex.cpp
#include<iostream>
int main(){
int a = 5;
int b = 3;
std::cout << a - b;
}
Without giving flag for a spesific target works fine:
clang++-11 -S ex.cpp -o ex.s
With --target=riscv32
flag:
clang++-11 --target=riscv32 -S ex.cpp -o ex.s
gives this error:
ex.cpp:1:9: fatal error: 'iostream' file not found
also without standard libraries gives no error even I give a spesific target.
I am searching for a solution for days but I couldn't find any proper solution for this problem, most of them says try to include gnu libraries and subfolders like -I/usr/include/x86_64-linux-gnu/c++/
but it doesn't work for me.
Please don't say use g++ compiler, for adding an optimization I need clang.
Actually I am trying to compile my codes for riscv target, linking with g++ and running with spike (doesn't differ --target=...
or -target ...
):
clang++-11 -target riscv32-unknown-elf -march=rv32gc -fno-addrsig -S ex.cpp -o ex.s
~/riscv/bin/riscv32-unknown-elf-g++ ex.s -o ex
~/riscv/riscv-isa-sim/build/spike --isa=RV32GC ~/riscv/riscv-pk/build/pk ex
And it works fine without include a standard library. Now, I want to ask that
Can I solve this problem simply?
or
Can I use clang directly from riscv bin utils like ~/riscv/bin/riscv32-unknown-elf-clang++
(I saw something like this on the net but couldn't find) adding and building a submodule to my riscv directory?
Edit: As @NateEldredge said, for x86_64 target triple should --target=x86_64-linux-gnu
but for riscv as a target triple riscv32-unknown-elf
I still have the same errors. Is there a proper target flag for riscv any other than --target=riscv32-unknown-elf
? Maybe I am missing that point.
std::string
andstd::vector
, which would be different libraries than C. Please update your tags and question about which language you are using. – Florinefloriofatal error: 'stdio.h' file not found
and so forth for any other library. – Testa--target
be a target triplet, not just an architecture? So--target=x86_64-linux-gnu
instead of justx86_64
. Runningclang -v
should show you what the default target triplet is. – Hoeve-v
), to see what libraries and include paths are implicitly used. – Turmoil--target=x86_64-linux-gnu
and it works but it is weird that without including a library, codes are compiling with just like--target=x86_64
but this is not the case :) Actually I need specify a target because I don't use on my x86, I need for riscv and I tried for riscv as a target tripleriscv32-unknown-elf
orriscv32-none-elf
and also tried for arm likearm-none-eabi
but noone works. Probably a proper target triple will work but couldn't find for riscv just findriscv32-unknown-elf
that doesnt work. – Testa--target
with the installed clang binary will search for its files in a specific place, which maybe is not where you have them installed. – Hoeve-DLLVM_TARGETS_TO_BUILD=all
option and used clang compiler from this built, because after llvm 9 i know llvm support came for riscv target. (All supported targets can be seen here.) I mean as llvm promised I should have been able to used clang for all targets with llvm in built but didn't work for me. – Testa