1

I just built a cross compiler using crosstools "mips-unknown-linux-gnu-gcc" and I compiled a hello world program. The compilation went fine using the command: "mips-unknown-linux-gnu-g++ hello.cpp -o hello" but when I run the command "./hello" I get the following error:

babbage-dasnyder 50% mips-unknown-linux-gnu-g++ hello.cpp -o hello
babbage-dasnyder 51% ./hello
./hello: Exec format error. Wrong Architecture.

Why is this? Did I make the wrong cross-compiler? I'm running this on a linux machine.

Just as a note, crosstools did say it could run a trivial program:

+ /home/seas/grad/dasnyder/opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/bin/mips-unknown-linux-gnu-gcc -static hello.c -o mips-unknown-linux-gnu-hello-static
+ /home/seas/grad/dasnyder/opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/bin/mips-unknown-linux-gnu-gcc hello.c -o mips-unknown-linux-gnu-hello
+ test -x /home/seas/grad/dasnyder/opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/bin/mips-unknown-linux-gnu-g++
+ cat
+ /home/seas/grad/dasnyder/opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/bin/mips-unknown-linux-gnu-g++ -static hello2.cc -o mips-unknown-linux-gnu-hello2-static
+ /home/seas/grad/dasnyder/opt/crosstool/gcc-3.4.5-glibc-2.3.6/mips-unknown-linux-gnu/bin/mips-unknown-linux-gnu-g++ hello2.cc -o mips-unknown-linux-gnu-hello2
+ echo testhello: C compiler can in fact build a trivial program.
testhello: C compiler can in fact build a trivial program.
+ test '' = 1
+ test '' = 1
+ test '' = 1
+ test 1 = ''
+ echo Done.
Done.
5
  • 2
    Are you running "./hello" on the same machine you compiled it ? Commented Jul 15, 2010 at 19:48
  • If you're on windows and you cross-compile a program for linux, do you expect your new linux program to run under windows? This situation isn't really any different... (If you do, then there's a much more abstract question you need to be asking) Commented Jul 15, 2010 at 19:50
  • Yes, I'm running it on the same machine, maybe I'm a bit confused, my goal is to compile a program on my linux machine so I can then disassemble the elf file and load it into a mips simulator that I built. So the elf file should be a MIPS elf file. I can see where that may not execute on the linux machine, but then how am I to test that the compiler worked correctly and that the compiled binary works correctly? Keep in mind that my mips simulator is under testing now and can't be used for such verification yet. Commented Jul 15, 2010 at 19:57
  • You could use -S to view the assembly output, or run it it someone else's MIPS emulator. Commented Jul 15, 2010 at 20:27
  • Good point, also, does anyone happen to know how I can verify that no shared libraries were used in compilation? I asserted the -static-libgcc, is this sufficient? Commented Jul 15, 2010 at 20:36

1 Answer 1

3

Just as a note, crosstools did say it could run a trivial program:

testhello: C compiler can in fact build a trivial program.

When you cross-compile to a different architecture, you are generating instructions for the new architecture and thus you may not be able to run these instructions on your current architecture. You are cross-compiling to be able to compile the code on a more powerful machine and then transfer it to the device for testing. If you are wanting to test the code directly on your machine you need to compile with your native architecture's compiler.

Sign up to request clarification or add additional context in comments.

1 Comment

Right, I've sense realized this. Fortunatly I have SESC to run the MIPS code on.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.