使用“cc”而不是“arm-none-eabi-as”

时间:2011-04-11 19:42:01

标签: linux makefile

使用makefile构建程序时遇到问题。当make尝试编译名为“startup.S”的程序集文件时,只有一个问题。看起来make使用编译器“cc”即使我在makefile中指定“arm-none-eabi-as”(看看变量AS)。

这是我的makefile:

SHELL := /bin/bash
ROOT := $(shell pwd)
INC := $(ROOT)/inc
SRC := $(ROOT)/src
STR := $(ROOT)/str
EXE := exe
AS := arm-none-eabi-as -mcpu=arm926ej-s -c -Wall -I $(INC) -I$(SRC) -I $(STR)
GCC := arm-none-eabi-gcc -mcpu=arm926ej-s -c -Wall -I $(INC) -I$(SRC) -I $(STR)
LDSCRIPT := test.ld
LD := arm-none-eabi-ld -T $(LDSCRIPT)
HEADERS := $(notdir $(wildcard $(INC)/*.h))
SOURCES_GCC := $(notdir $(wildcard $(SRC)/*.c))
SOURCES_AS := $(notdir $(wildcard $(STR)/*.S))
OBJECTS_GCC := $(SOURCES_GCC:.c=.o)
OBJECTS_AS := $(SOURCES_AS:.S=.o)
VPATH := $(STR):$(SRC):$(INC)

all : $(EXE)
    @echo konec postopka: izvrsljiv program po imenu $(EXE) se nahaja v mapi $(ROOT)
$(EXE) : $(OBJECTS_AS) $(OBJECTS_GCC)
    @echo objekti so: $(OBJECTS_AS) $(OBJECTS_GCC)
    @echo headerji so: $(HEADERS)
    @echo linkanje objektov v izvrsljiv program...
    $(LD) -o $@ $^
%.o : %.S %h
    @echo prevajanje ASSEMBLY izvornih datotek...
    $(AS) -o $@  $<
%.o : %.c %h
    @echo prevajanje C izvornih datotek...
    $(GCC) -o $@ $<
.PHONY : clean
clean :
    @echo brisanje objektov
    rm *.o
    @echo brisanje izvrsljivega programa
    rm $(EXE)

以下是在终端中输入comand make时出现的错误。它清楚地告诉“cc”不理解汇编语言,这个错误在某种程度上是可以预料的。

cc    -c -o startup.o /home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S: Assembler messages:
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:4: Error: no such instruction: `b Reset_Handler'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:5: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:6: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:7: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:8: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:9: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:10: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:11: Error: no such instruction: `b .'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:14: Error: no such instruction: `ldr sp,=stack_top'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:15: Error: no such instruction: `bl c_entry'
/home/ziga/Dropbox/diploma/86x_linux/IDE_eclipse/eclipse_projects/makefile_8/str/startup.S:16: Error: no such instruction: `b .'

如果我尝试使用“arm-none-eabi-as startup.S”手动编译它,它编译得很好......

我的问题是,为什么make使用cc代替arm-none-eabi-as?我在这里缺少什么?

在我提出所有建议后,我设法制作了一个makefile,看起来像这样,它正在运行:

SHELL := /bin/bash
ROOT := $(shell pwd)
INC := $(ROOT)/inc
SRC := $(ROOT)/src
STR := $(ROOT)/str
EXE := exe
AS := arm-none-eabi-as -mcpu=arm926ej-s -c -Wall -I $(INC) -I$(SRC) -I $(STR)
CC := arm-none-eabi-gcc -mcpu=arm926ej-s -c -Wall -I $(INC) -I$(SRC) -I $(STR)
LDSCRIPT := ldscript_iram_gnu.ld
LD := arm-none-eabi-ld -T $(LDSCRIPT)
HEADERS := $(notdir $(wildcard $(INC)/*.h))
SOURCES_CC := $(notdir $(wildcard $(SRC)/*.c))
SOURCES_AS := $(notdir $(wildcard $(STR)/*.S))
OBJECTS_CC := $(SOURCES_CC:.c=.o)
OBJECTS_AS := $(SOURCES_AS:.S=.o)
VPATH := $(STR):$(SRC):$(INC)

all : $(EXE)
    @echo konec postopka: izvrsljiv program po imenu $(EXE) se nahaja v mapi $(ROOT)
$(EXE) : $(OBJECTS_AS) $(OBJECTS_CC)
    @echo objekti so: $(OBJECTS_AS) $(OBJECTS_CC)
    @echo headerji so: $(HEADERS)
    @echo linkanje objektov v izvrsljiv program...
    $(LD) -o $@ $^
%.o : %.S
    @echo prevajanje ASSEMBLY izvornih datotek...
    $(AS) -o $@  $<
%.o : %.h

%.o : %.c
    @echo prevajanje C izvornih datotek...
    $(CC) -o $@ $<
%.o : %.h

.PHONY : clean
clean :
    @echo brisanje objektov
    rm *.So
    rm *.o
    @echo brisanje izvrsljivega programa
    rm $(EXE)

当我尝试在其他项目(从头开始构建我的makefile的项目)中使用相同的makefile时,它也有相同的树结构,我得到一些错误:

make all 
objekti so: timer_example.o
headerji so: ea3131_board.h ffconf.h ff.h integer.h lpc313x_cgu_driver.h lpc313x_cgu.h lpc313x_cgu_switchbox.h lpc313x_chip.h lpc313x_crc_driver.h lpc313x_dmac.h lpc313x_dma_driver.h lpc313x_evt_driver.h lpc313x_evt_router.h lpc313x_i2c_driver.h lpc313x_i2c.h lpc313x_intc_driver.h lpc313x_intc.h lpc313x_ioconf_driver.h lpc313x_ioconf.h lpc313x_mci_driver.h lpc313x_mci.h lpc313x_nandc.h lpc313x_nand_driver.h lpc313x_spi_driver.h lpc313x_spi.h lpc313x_sysreg.h lpc313x_timer_driver.h lpc313x_timer.h lpc313x_uart_driver.h lpc313x_uart.h lpc313x_wdt_driver.h lpc313x_wdt.h lpc31xx_vmem_driver.h lpc_api.h lpc_arm922t_arch.h lpc_arm922t_cp15_driver.h lpc_arm_arch.h lpc_bmp.h lpc_colors.h lpc_fat16.h lpc_fat16_private.h lpc_fonts.h lpc_heap.h lpc_helvr10.h lpc_irq_fiq.h lpc_lbecc.h lpc_lcd_params.h lpc_line_parser.h lpc_nandflash_params.h lpc_params.h lpc_rom8x16.h lpc_rom8x8.h lpc_sdmmc.h lpc_string.h lpc_swim_font.h lpc_swim.h lpc_swim_image.h lpc_types.h lpc_winfreesystem14x16.h lpc_x5x7.h lpc_x6x13.h
linkanje objektov v izvrsljiv program...
arm-none-eabi-ld -T ldscript_iram_gnu.ld -o exe timer_example.o
ea3131_startup_entry.o: In function `clearzi_exit':
(.text+0x170): undefined reference to `ea3131_init'
timer_example.o: In function `timer0_user_interrupt':
timer_example.c:(.text+0x15c): undefined reference to `timer_ioctl'
timer_example.o: In function `uart_string_write':
timer_example.c:(.text+0x1dc): undefined reference to `strlen'
timer_example.c:(.text+0x208): undefined reference to `uart_write'
timer_example.o: In function `c_entry':
timer_example.c:(.text+0x258): undefined reference to `ea3131_board_init'
timer_example.c:(.text+0x260): undefined reference to `cp15_set_vmmu_addr'
timer_example.c:(.text+0x268): undefined reference to `int_initialize'
timer_example.c:(.text+0x274): undefined reference to `int_install_irq_handler'
timer_example.c:(.text+0x280): undefined reference to `timer_open'
timer_example.c:(.text+0x2a4): undefined reference to `timer_ioctl'
timer_example.c:(.text+0x2bc): undefined reference to `timer_ioctl'
timer_example.c:(.text+0x2d4): undefined reference to `timer_ioctl'
timer_example.c:(.text+0x2e0): undefined reference to `uart_open'
timer_example.c:(.text+0x2f8): undefined reference to `memcpy'
timer_example.c:(.text+0x32c): undefined reference to `timer_ioctl'
timer_example.c:(.text+0x334): undefined reference to `int_enable'
timer_example.c:(.text+0x38c): undefined reference to `sprintf'
make: *** [exe] Error 1

我认为我的makefile现在运行正常,但我的项目中有一些未解析的引用与我的makefile无关。 我仍然需要你的构造,我的makefile正常。谢谢大家。

问候。

2 个答案:

答案 0 :(得分:5)

尝试使用CC代替GCC(这是默认make规则中使用的变量),但在这种情况下,它发现了另一个问题:您的规则被忽略了。

什么是“%h”应该做什么?

另请注意,您的“echo”命令未执行 - 另一个暗示您的规则未被make考虑

答案 1 :(得分:2)

用于汇编的.o文件被.c文件的.o规则覆盖。您无需在.o中结束目标文件。请尝试以下方法:

OBJECTS_AS := $(SOURCES_AS:.S=.os)

您的装配规则变为:

%.os : %.S %h
    @echo prevajanje ASSEMBLY izvornih datotek...
    $(AS) -o $@  $<

当然你可以我们.o_assembly或其他什么。只有在使用隐式规则时,目标文件才必须以.o结尾。