I am trying to compile a very simple program using the -m32 flag.
If I try to do this using gcc -m32 it works just fine(I have the needed libs)
Yet, when I add this flag to my flags in a makefile, I get a weird error
This is the makefile that I have
CC=gcc
CFLAGS=-m32 -O1 -W -Wall -pedantic -std=c99
all: main.o
$(CC) -o main main.o
rm main.o
clean:
rm main
The error that I receive is the following
gcc -o main main.o
/usr/bin/ld: i386 architecture of input file `main.o' is incompatible with i386:x86-64 output
collect2: ld returned 1 exit status
make: *** [all] Error 1
Can someone please tell me what does this mean? and how can I fix it?
As for the code, the code does NOTHING except printing ‘hello world’
I am using GCC 4.4.3 under Linux 2.6.35 64-bits
Your mistake is that you don’t pass
-m32to the linker.You actually need to change your
Makefileto look like this:An even better approach would be the following
Makefile:In the later you just say that main depends on
main.oandGNU Makewill invoke the linker with theLDFLAGSas arguments for you as it invokes the compiler with theCFLAGSas arguments for themain.o“The targets which .INTERMEDIATE depends on are treated as intermediate files. See section Chains of Implicit Rules. .INTERMEDIATE with no dependencies marks all file targets mentioned in the makefile as intermediate.” Special Built-in Target Names