I understand what are cross compilers and why are they used. But in an interview I was asked that in what ways cross compilers are different from the normal compilers. I told them the purpose of the cross compilers. Also, the memory map will be different for them. But the guy does not seems to be convinced. Can any one tell me the basic differences from normal compilers?
-
What do you believe the purpose to be? – Matt K Dec 01 '10 at 14:03
-
1Some interviewers are good at remaining deadpan no matter what your answer is. Maybe you did convince him but he didn't want to react strongly to your answer. – Cameron Skinner Dec 01 '10 at 14:05
-
A good tip for that sort of situation is to ask what they believe the answer to be. Even if you don't get the job you learn something new. I had a similar situation when asked about multi-threading in an interview. Multi-threading is very very over-used, usually unnecessarily. The interviewer asked when it would be useful and I couldn't think of a really good example and asked him the same question. I didn't get the job but I did increase my knowledge of programming with a really good answer. – AlastairG Dec 01 '10 at 14:08
-
How did you answer the question? Without knowing what you said it's pretty difficult to help you. – user207421 Dec 02 '10 at 09:39
-
@EJP : I told him that for running the images and executables on different architecture other than that of where we write the code we use cross compilers. I gave him an example also. Explained him that how the word sizes and the memory maps differ for different architectures and so we need Cross Compilers. – iSegFault Dec 02 '10 at 17:35
-
Sounds like a decent answer to me. I would have mentioned instruction sets before word sizes and memory maps myself. I don't think you need to worry really. If he doesn't know the right answer you don't want to work there anyay, you'll only make him feel threatened, and if he expects word-perfect answers he is really just showing off IMO. – user207421 Dec 03 '10 at 00:51
6 Answers
A cross compiler is a compiler capable of creating executable code for a platform other than the one on which the compiler is run. Cross compiler tools are used to generate executables for embedded system or multiple platforms. It is used to compile for a platform upon which it is not feasible to do the compiling, like microcontrollers that don't support an operating system. It has become more common to use this tool for paravirtualization where a system may have one or more platforms in use. - WIKI
according to some sources you cant just say java (or any others uses runtime environment or virtual machines) as cross compilers.
really cross compilers can target many platforms from one source code. but you may have to build each of them separately

- 7,147
- 8
- 52
- 102

- 7,133
- 1
- 21
- 27
-
this is what cross compiler does. In what respect they are different from normal compilers? – iSegFault Dec 01 '10 at 14:06
-
replace 'cross' with 'normal' and later, substitute in '.... for a platform on which the compiler is run.' Then create a sentence that describes that difference. – KevinDTimm Dec 01 '10 at 14:09
-
Well, many compilers that aren't technically cross-compilers can do that too, depending on how your listener interprets the word "platform". I'd be more inclined to define it negatively: An executable built with a cross-compiler cannot be run natively on the platform it is compiled on. – T.E.D. Dec 01 '10 at 14:16
I think the cross-compiler use different assembly language code. for example, the i386 and arm use different assembly language code.

- 167
- 1
- 1
- 7
A normal compiler can be a cross compiler. Take GCC for example.
Quoting from Wikipedia:
GCC, a free software collection of compilers, can be set up to cross compile. It supports many platforms and languages. However, due to limited volunteer time and the huge amount of work it takes to maintain working cross compilers, in many releases some of the cross compilers are broken.[citation needed]
GCC requires that a compiled copy of binutils be available for each targeted platform. Especially important is the GNU Assembler. Therefore, binutils first has to be compiled correctly with the switch --target=some-target sent to the configure script. GCC also has to be configured with the same --target option. GCC can then be run normally provided that the tools, which binutils creates, are available in the path.

- 46,442
- 10
- 75
- 103
-
But this does not answers how the cross compilers are different from compilers – iSegFault Dec 01 '10 at 14:07
-
@ravspratapsingh: somebody correct me if I'm wrong, but I don't think you can have a cross compiler that's also NOT a compiler. A cross compiler is a compiler with added ability to generate code for a different target platform than the host platform where compilation is invoked. If that kind of answer didn't satisfy the interviewer, then I wonder what his answer would have been. – darioo Dec 01 '10 at 14:11
-
-
The main difference is that with a "normal compiler" you can run the compiled executable right on the machine you compiled it on. With a cross compiler you will have to upload it to a system using its targetted platform somehow to run it and see if it works. (Or use some kind of emulator or VM).
That's the only big difference, really. It adds an extra step or two in your edit-compile-debug cycle. It can be a bit of a pain. Then again, typically cross-compilers are used for realtime or embedded systems where a likely result from a bug is a total system crash. If that can happen, it would be more of a pain to run on your development system, as you'd be constantly having to wait for reboots and restart your editor, reload working files into your editor, etc.

- 44,016
- 10
- 73
- 134
Some cross-compilers have pluggable code generators, so you simply indicate that type of code you want generated and they will look up the appropriate generator and invoke the proper assembler for the target you specify. For the most part, though, a compiler's a compiler; they all do the same thing.

- 3,060
- 21
- 23