I have a makefile that calls arm-none-eabi-g++ to compile a bunch of files. If I give the files a .c extension, it works. If I change the extension to .cc, it looks like g++ is doing the compilation instead of arm-none-eabi-g++. I'm specifying -mcpu=cortex-m0 -mthumb. Here is the makefile:
CXX := arm-none-eabi-g++
# -I/usr/lib/arm-none-eabi/include\: since we're compiling with nostdinc and nostdlib, include this directory to grab necessary files
CFLAGS := \
-nostdinc\
-I.\
-I../arch/cortex-m0+\
-I../devices\
-I../libc\
-I/usr/lib/arm-none-eabi/include\
-O0\
-ffunction-sections\
-fdata-sections\
-Wall\
-fmessage-length=0\
-mcpu=cortex-m0\
-mthumb\
-mfloat-abi=soft\
-gdwarf-2\
-g3\
-gstrict-dwarf\
-Wno-unused-but-set-variable\
-Wno-attributes\
-fno-builtin\
-fno-exceptions
objects := \
../libc/math.o\
../libc/malloc.o
radio : $(objects)
math.o : ../libc/math.c ../libc/math.h
$(CXX) $(CFLAGS) -c ../libc/math.c
malloc.o : ../libc/malloc.cc ../libc/malloc.hh
$(CXX) $(CFLAGS) -c ../libc/malloc.cc
clean :
rm radio.elf radio.map $(objects)
and here's the output from make:
marlon@marlon-Z68X-UD3H-B3:~/projects/firmware$ make
cc -nostdinc -I. -I../arch/cortex-m0+ -I../devices -I../libc -I/usr/lib/arm-none-eabi/include -O0 -ffunction-sections -fdata-sections -Wall -fmessage-length=0 -mcpu=cortex-m0 -mthumb -mfloat-abi=soft -gdwarf-2 -g3 -gstrict-dwarf -Wno-unused-but-set-variable -Wno-attributes -fno-builtin -fno-exceptions -c -o ../libc/math.o ../libc/math.c
cc: warning: ‘-mcpu=’ is deprecated; use ‘-mtune=’ or ‘-march=’ instead
cc: error: unrecognized command line option ‘-mthumb’
cc: error: unrecognized command line option ‘-mfloat-abi=soft’
make: *** [../libc/math.o] Error 1
I solved the problem by making sure I set both CC and CXX in the makefile:
CC := arm-none-eabi-gcc
CXX := arm-none-eabi-g++
Note the discrepancy between
objects := ../libc/math.o ...
and
math.o: ...
Make has a rule for radio
which depends on objects
, thus depends on ../libc/math.o
. Since that doesn't exist, Make goes looking for a rule to build it. Now, math.o
in the current directory is a different thing to ../libc/math.o
, so Make finds no user-defined rules for what it wants, and ends up falling back to its implicit rules (which build ".c" files with $CC and ".cc" files with $CXX).
In other words, your custom rules are for irrelevant targets - you can simply specify the exact path to make things work as expected, although if you ultimately want something more general it'd be worth having a look into how wildcards and pattern rules work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.