在使用makefile构建程序时,我遇到了一个问题。当make试图编译名为"startup.S“的程序集文件时,只有一个问题。它看起来像make编译器"cc“,即使我在makefile中指定了”arm- at 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- to eabi-作为startup.S”手动编译它,它编译得很好.
我的问题是,为什么要使用cc而不是手臂-无-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无关。,我仍然需要你们的构图,我的制作文件做得很好。,谢谢大家。
致以问候。
发布于 2011-04-11 19:47:59
尝试使用CC代替GCC (它是默认的make规则中使用的变量),但在这种情况下,它发现了另一个问题:您的规则被忽略了。
"%h“应该做什么?
还请注意,您的"echo“命令没有执行--这是一个提示,即make没有考虑您的规则。
发布于 2011-04-12 10:14:40
用于程序集的.o文件被用于.c文件的.o规则覆盖。您不必在.o中结束您的对象文件,而是尝试以下操作:
OBJECTS_AS := $(SOURCES_AS:.S=.os)而您的组装规则是:
%.os : %.S %h
@echo prevajanje ASSEMBLY izvornih datotek...
$(AS) -o $@ $<你当然可以让我们.o_assembly什么的。只有在使用隐式规则时,对象文件才必须以.o结尾。
https://stackoverflow.com/questions/5626606
复制相似问题