简体   繁体   English

arm-none-eabi-g ++尝试为桌面而不是arm进行编译

[英]arm-none-eabi-g++ is trying to compile for desktop instead of arm

I have a makefile that calls arm-none-eabi-g++ to compile a bunch of files. 我有一个生成文件,调用arm-none-eabi-g ++来编译一堆文件。 If I give the files a .c extension, it works. 如果我给文件加.c扩展名,它就可以工作。 If I change the extension to .cc, it looks like g++ is doing the compilation instead of arm-none-eabi-g++. 如果我将扩展名更改为.cc,则似乎g ++正在执行编译,而不是arm-none-eabi-g ++。 I'm specifying -mcpu=cortex-m0 -mthumb. 我指定-mcpu = cortex-m0 -mthumb。 Here is the makefile: 这是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: 这是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: 我通过确保在makefile中设置CC和CXX来解决了这个问题:

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 . Make的radio规则取决于objects ,因此取决于../libc/math.o Since that doesn't exist, Make goes looking for a rule to build it. 既然不存在,Make就去寻找建立规则。 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). 现在, math.o 在当前目录是不同的东西../libc/math.o ,所以要认定它想要的东西没有用户定义的规则,并最终回落至其隐含规则 (其中建设”。带有$ CC的c“文件和带有$ CXX的” .cc“文件)。

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. 换句话说,您的自定义规则适用于不相关的目标-您可以简单地指定使事情按预期工作的确切路径,尽管如果您最终想要更通用的内容,则值得一看通配符和模式规则的工作方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM