i try to mix files . For example , if i have file1.o and have file2.o , all of them don't have main function , then le1_file2.o is the result of those files . So i have used 2 things :
Using of linker and makefile:
linker.ld:
OUTPUT_FORMAT(elf32-i386)
SECTIONS
{
.text : {*(.text)}
.data : {*(.data)}
.rodata : {*(.rodata)}
.bss :
{
*(COMMON)
*(.bss)
}
end = .; _end = .; __end = .;
}
Makefile:
CC =gcc
OBJ = file1.o file2.o
all : file1_file2.o
file1_file2.o: $(OBJ)
ld -m elf_i386 --oformat=binary -Tlinker.ld $^ -o $@
%.o : %.c
@$(CC) -o $@ -c $< -m32 -g -ffreestanding -fno-PIC -fno-stack-protector -Werror
Using only a makefile:
Makefile:
CC =gcc
OBJ = file1.o file2.o
all : file1_file2.o
file1_file2.o: $(OBJ)
$(CC) $^ -o $@ -m32 -g -ffreestanding -fno-PIC -fno-stack-protector -Werror
%.o : %.c
@$(CC) -o $@ -c $< -m32 -g -ffreestanding -fno-PIC -fno-stack-protector -Werror