0

I am using arm-non-eabi-gcc as cross compiler.

I have created a simple hello world program in eclipse.

I am able to compile the program using arm-non-eabi-gcc, and helloworld.out[arm/le] file is getting generated but I cannot run it as it is runable only on arm not on windows x86-64.

I know I can use cygwin or mingw to compile the code and I will be able to run the program on windows easily but, I want to use arm-non-eabi-gcc as cross compiler only.

I want to know how can I use the arm-non-eabi-gcc as cross compiler or which flags I need to include in my make file or eclise tool chain setting and create a elf file which can be easily run on windows x86-64.

Note: the generated binary will be always run on windows not any arm system it is just that my project workspace has other projects which use arm-none-eabi-gcc so I want use same and I don't want cygwin or mingw.

My complete workspacr and other projects are easily movable as I keep arm-non-eabi-gcc exe in project directory. Using cygwin or mingw makes compilation and running the binary easy but we need to install these when we change system.

Any guidance or help will be appreciated.

Thank you.

ams
  • 315
  • 4
  • 17
  • 3
    Sorry, but you can't run arm code on x86-64. `how can I use the arm-non-eabi-gcc as cross compiler .. run on windows x86-64.` You can't. x86 is not arm. You can't run x86 code on arm and can't run arm code on x86. `Any guidance` Research what is x86 and arm _architectures_, what is a compiler and what does it do, what does cross-compiling means. Then interest yourself in emulators and virtualizations. – KamilCuk Sep 27 '21 at 15:07
  • .. or you can run *some* ARM code on an emulator such as QEMU. – Eugene Sh. Sep 27 '21 at 15:26
  • @KamilCuk Hi thank you for reply, I know we can't run arm code on x86 and vice versa. I just want to know is there any way with which we can generate a binary which can be run on x86 using arm-none-eabi-gcc or else we can convert the binary generated using arm-none-eabi-gcc to a binary which can be run on x86-64 – ams Sep 27 '21 at 16:13
  • 1
    `using arm-none-eabi-gcc` You can't "run using" a compiler. Compiler does not "run" executables. `we can convert the binary generated using arm-none-eabi-gcc to a binary which can be run on x86-64` Potentially this would be possible, basically create a mapping of every assembly instruction from arm into x86, arm is RISC architecture, so it should be simple, then translate. But it's an _enormous_ task with hard edge cases. Still `using arm-none-eabi-gcc` You can't "convert" binaries from one architecture to another using a C compiler. C compiler compiles C code. – KamilCuk Sep 27 '21 at 16:13
  • @Eugene Sh Hi thank you for reply, but this would mean I need to use qemu. And I don't require it cause the final binary I am always going to run on windows not on any arm system. – ams Sep 27 '21 at 16:15
  • @KamilCuk the generated binary will be always run on windows not any arm system it is just that my project workspace has other projects which use arm-none-eabi-gcc so I want use same and I don't want cygwin or mingw. – ams Sep 27 '21 at 16:19
  • 2
    `will be always run on windows` so do not use `arm-none-eabi-gcc` and use a different compiler that generates code that can be run on windows. `so I want use same` it is impossible. `I don't want cygwin or mingw` use something else then. – KamilCuk Sep 27 '21 at 16:20
  • 1
    The whole point of a cross compiler is to make executables that won't run natively on the current system. Either use an emulator, or don't use the cross compiler. Unlike clang, GCC doesn't have an option like `-target x86-64-windows`. `arm-none-eabi-gcc` can *only* make ARM binaries. – Peter Cordes Sep 27 '21 at 16:28
  • technically you can make a cross compiler that does build for the native target, seems silly but you can. better to say that the term cross compiler is intended to mean when you are making binaries for some non-native target. to cross the binary from where it is built to where it is used.... – old_timer Sep 27 '21 at 19:33

1 Answers1

0

The whole point of a cross compiler is to make executables that won't run natively on the current system. Either use an emulator, or don't use the cross compiler.

Unlike clang, GCC doesn't have an option like -target x86-64-windows. Your arm-none-eabi-gcc can only make ARM binaries.

So I guess it doesn't hurt to ask, but the answer here is a clear and obvious "no" with all the constraints you put in place, like not using an emulator, and using a compiler that can only make ARM binaries.

If you want executables you can run on x86-64 Windows, build them outside your IDE (e.g. with a simple Makefile on the command line), or configure that project differently from the cross-compile projects in your IDE.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847