Reputation: 656
I have previously write a compilation line which is working. Howewer, my Makefile, which generates more or less the same thing, isn't successfully compiling.
Command line (working) :
sh3eb-elf-gcc -m3 -mb -ffreestanding -nostdlib -T addin.ld src/crt0.s src/BTKOM.cpp src/bluetooth.cpp src/syscall.s -o addin.elf -Iinclude -L libs/ -lgcc -lmonochrome -lfx -O2 -fno-exceptions
Makefile :
CC = sh3eb-elf-gcc
SRCDIR = src
INCLDIR = include
LIBDIR = libs
EXTENSIONS = c cpp s
LIBS = -lgcc -lmonochrome -lfx
WFLAGS = -Wall
CFLAGS = -I $(INCLDIR) $(WFLAGS)
LFLAGS = -m3 -mb -ffreestanding -nostdlib -T addin.ld -L $(LIBDIR) $(LIBS) -O2 -fno-exceptions
SRCS := $(SRCS) $(foreach EXT,$(EXTENSIONS),$(wildcard $(SRCDIR)/*.$(EXT)))
OBJS := $(OBJS) $(foreach EXT,$(EXTENSIONS),$(patsubst $(SRCDIR)/%.$(EXT),%.o,$(wildcard $(SRCDIR)/*.$(EXT))))
OUT = addin
all : $(OUT).elf
$(OUT).elf : $(OBJS)
$(CC) $(LFLAGS) -o $@ $^
$(OBJS) : $(SRCDIR)/$(SRCS)
$(CC) $(CFLAGS) -c $(SRCS)
clean:
rm -f *.o
cleaner:
rm -f *.o $(OUT).elf $(OUT).g1a $(OUT).bin
Generated lines from makefile :
sh3eb-elf-gcc -I include -Wall -c src/MonochromeLib.c src/BTKOM.cpp src/bluetooth.cpp src/syscall.s src/crt0.s
sh3eb-elf-gcc -m3 -mb -ffreestanding -nostdlib -T addin.ld -L libs -lgcc -lmonochrome -lfx -O2 -fno-exceptions -o addin.elf MonochromeLib.o BTKOM.o bluetooth.o syscall.o crt0.o
Output :
BTKOM.o: In function `_main':
BTKOM.cpp:(.text+0xc4): undefined reference to `_memset'
BTKOM.cpp:(.text+0xec): undefined reference to `_GetKey'
bluetooth.o: In function `Bluetooth::Bluetooth()':
bluetooth.cpp:(.text+0xa0): undefined reference to `_srand'
bluetooth.cpp:(.text+0xa4): undefined reference to `_rand'
bluetooth.cpp:(.text+0xac): undefined reference to `_memcpy'
...
Upvotes: 1
Views: 91
Reputation: 21020
There's a reason the built-in linking rule is defined as
$(LINK.o) $^ $(LOADLIBES) $(LDLIBS) -o $@
LINK.o
is
$(CC) $(LDFLAGS) $(TARGET_ARCH)
You should find it works by rewriting your makefile as
LDLIBS := -lgcc -lmonochrome -lfx
LDFLAGS := -nostdlib -T addin.ld -L libs
$(OUT).elf: $(OBJS)
$(LINK.o) $^ $(LDLIBS) -o $@
Note that -O2
, ffreestanding
and -fno-exceptions
are compilation options, not linking options (and I think -m3
and -mb
are as well).
Upvotes: 2