2

I am trying to compile a very simple Hello World C-program to MIPS assembly on a winx64 machine using llvm/clang.

I have searched for this issue and whilst there are a number of threads with similar topics they almost exclusively use linux and more often than not do not provide any form of solution.

I was under the impression that if I get the latest LLVM binaries and install that on my windows machine I would be able to cross compile say C to MIPS assembly right out of the box. Is that not the case or am I missing something?

If I target anything besides windows I get an error for the missing header file stdio.h Isn´t the thing designed to do exactly that? Convert my C code into the given target asm?

Also there seems no Config.h on windows like there is on linux to change certain hardcoded paths.

Maybe I am totally misunderstanding something about llvm/clang. Hope anyone can help point me in a direction to solve this.

Thanks

AlexS87
  • 21
  • 2
  • "I get an error for the missing header file stdio.h Isn´t the thing designed to do exactly that? Convert my C code into the given target asm?" - but if you're including stdio.h then you're asking it to do more than that: you're asking it to build against a C runtime library that it can't find. I know GCC better than LLVM but for GCC you'd need to give it header files and libraries from the target system e.g. copy them off a MIPS Linux distribution. (And it would need to have had these to build the compiler in the first place.) But LLVM may be different. Where will you run this binary? – Rup Oct 04 '18 at 10:51
  • 2
    LLVM can handle many different varieties of crosscompilation, but the binaries aren't built with all that. If you want to crosscompile, you generally have to build from source. (And, as @Rup says, you have provide header files etc. for the target rather than the host system.) – arnt Oct 04 '18 at 10:58
  • Thanks for your input, the picture is clearer now. I am not trying to build a binary, just the mips assembly to run it on a simulated mips processor. I will look for the header files from MIPS and try to pass them as the include dir. – AlexS87 Oct 04 '18 at 14:19
  • 1
    clang on Godbolt works for many random architectures, like `-target sparc64` or `-target mips`, like in the Godbolt link in my answer on [What exact rules in the C++ memory model prevent reordering before acquire operations?](https://stackoverflow.com/a/52636008). https://godbolt.org/z/zT2rkp. Sometimes you run into problems with headers, but for some stuff it works great if you just want to see how compilers do something on MIPS or whatever other ISA. – Peter Cordes Oct 04 '18 at 17:54

1 Answers1

0

https://sites.google.com/site/lccretargetablecompiler/

https://github.com/drh/lcc

LCC a retargetable C compiler ran under windows and could output x86, Mips R3000, SPARC, or ALPHA processors.

Check it out to produce your mips assembly code.

Or look at clang/llvm compiler https://llvm.org/docs/HowToCrossCompileLLVM.html