Wrong ELFCLASS?!?

Posted September 11, 2009 at 12:14 pm in Programming

In my programming class this semester which deals with ADTs and algorithms we had to implement our own ADT to handle strings. Normally I will work on my programming assignments in the campus computer lab to avoid any possible issues involving different architectures, versions, libraries, etc. than what I may have at home. (Yes, I realize I could open a session at home on the campus lab systems but I like knowing that it’ll work without any questions later and the lab offers me more space to spread out my materials.) Anyways, I decided that it’s the start of the semester and that the first lab wouldn’t be too difficult and that I could probably complete it at home.

I did a little research involving IDEs and decided to give NetBeans a shot. After the packages had been installed I fired up NetBeans and took it for a spin. Deciding that I liked NetBeans, I began to code my ADT lab assignment and had no issues compiling, linking, or running my code. About an hour later I finished the lab assignment and uploaded the required lab files to my account on the campus lab systems.

The next day, in lab, however, I noticed that the lab had new computers from the previous semester. After logging in and playing around a bit I tried to compile the code I had written the previous night at home. Lo and behold, g++ spit out an error:

ld: fatal: file lab1.o: wrong ELF class: ELFCLASS64

I think this compile error may be one of the most humorous ones I’ve seen. Wrong ELF class? Think about that one for a minute. If you were somewhat sketchy on what an ELF class was and someone said to you that you have the wrong ELF class, what would you think? If you don’t believe me, head on over to Google and type “what is ELFCLASS” and look at the second result.

This error simply means that the object should be linked into a 64-bit object and if ld() isn’t made aware of this, it will generate an ELFCLASS64 error message. Depending on your system, your compiler may include additional files for compilation along with your file. If this occurs and one of those additional files is in 32-bit format (assuming you’re using 64-bit) and the file is handled first by the link-editor then you’ll receive an ELFCLASS error because ld() entered 32-bit mode. I found a nice writeup of this error at Surfing With a Linker Alien if you wish to learn more.

I fixed the ELFCLASS64 error by editing my makefile. I had to edit the system command for each target by including something similar to:

g++ -c -m32 lab1.cc

The “-m32″ and “-m64″ flags will generate code for 32-bit systems (-m32) and 64-bit systems (-m64). So if you compile code at home on a 64-bit machine and attempt to compile it on a 32-bit machine you’ll need to add the “-m32″ flag in your compile command.


Commentary

+

Add Your Comment

Your email address will never be shared or published.

Your Name:

Your Email:

Your Site: