-3

I am trying to convert .c files for ARM (ARMv7l for Raspberry Pi2) but I could not find any online converter or understand how it works. Previously these .c files were executable in Windows platform and thus unable to execute on Pi's arm architecture. Does anybody can assist me in this?

Roy.L
  • 1
  • 1
  • 1
  • 3
  • 3
    You should be able to compile C code for whatever platform you want. What are these files and what's the problem you're having? – Carl Norum May 31 '17 at 04:31
  • 2
    You need a compiler, in this case a cross compiler for the ARM platform. Maybe you can try clang. It comes with the ARM target. The assembly can be generated using the `-S` flag with the clang compiler. – Ajay Brahmakshatriya May 31 '17 at 04:42
  • @CarlNorum I am trying to setup a memory reader software in c using Raspberry Pi2, however the binaries and platform are different – Roy.L May 31 '17 at 06:29
  • @AjayBrahmakshatriya I have installed the gnu, gcc, libc and binutils compilers using Raspbian terminal, are that appropriate enough to cross compile? I have encountered some errors during cross-compiling stages – Roy.L May 31 '17 at 06:29
  • 1
    You need not compile the code on your Raspberry. You can compile it on your desktop with appropriate target and then move the files to the Rasp. – Ajay Brahmakshatriya May 31 '17 at 06:31
  • 1
    Not that if your code makes much use of the API calls etc in '#include "windows.h" ', then you may have a considerable task in front of you;( – ThingyWotsit May 31 '17 at 07:41
  • yes if you have setup gcc, etc on raspian then you are ready to go, it is not a cross compiler at that point it is a native compiler and works even better. – old_timer May 31 '17 at 10:13
  • How do i actually change the API of "include #windows.h" in my .c file to the appropriate one to be use for Pi? Any guides or suggestions? – Roy.L Jun 01 '17 at 08:55

1 Answers1

1

Any c compiler can generate assembly code from C code, if your objective is specifically to generate assembly code for arm then you'll need a cross compiler such as the GNU arm embedded toolchain.

For gcc on particular you just need to use the -S option when compiling, so the line looks something like:

gcc -S -source.c -o output.s

Of course you'll need to include any headers and include directories for it to compile.

if you simply want to cross compile it, then simply do the full compilation assemblage and linking process. Depending on how low level the c code is it's actually possible for it not to work on the pi 2 (but it will compile)

Makogan
  • 8,208
  • 7
  • 44
  • 112
  • Thanks will try it out! – Roy.L Jun 13 '17 at 06:22
  • when i input gcc -S "scanAdd.c -o scanAdd.s" with error: scanAdd.c:1:21: fatal error: windows.h: No such file or directory #include ^ compilation terminated. Why is this error occurring again? hmm – Roy.L Jun 13 '17 at 08:44