Compiling to 32-bit using make
c, makefile, x86
Solution
Your mistake is that you don't pass `-m32` to the linker.
You actually need to change your `Makefile` to look like this:
CC=gcc
CFLAGS=-m32 -O1 -W -Wall -pedantic -std=c99
LDFLAGS = -m32
all: main.o
$(CC) $(LDFLAGS) -o main main.o
rm main.o
clean:
rm main
An even better approach would be the following `Makefile`:
CC=gcc
CFLAGS=-m32 -O1 -W -Wall -pedantic -std=c99
LDFLAGS=-m32
.INTERMEDIATE: main.o
all: main
main: main.o
clean:
-rm main
In the later you just say that main depends on `main.o` and `GNU Make` will invoke the linker with the `LDFLAGS` as arguments for you as it invokes the compiler with the `CFLAGS` as arguments for the `main.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
Problem
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