2011-04-11 31 views
2

使用makefile編譯程序時出現問題。 make嘗試編譯名爲「startup.S」的程序集文件時只有一個問題。它看起來像使用編譯器「cc」,即使我在makefile中指定「arm-none-eabi-as」(查看變量AS)。使用「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) 
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 [email protected] $^ 
%.o : %.S %h 
    @echo prevajanje ASSEMBLY izvornih datotek... 
    $(AS) -o [email protected] $< 
%.o : %.c %h 
    @echo prevajanje C izvornih datotek... 
    $(GCC) -o [email protected] $< 
.PHONY : clean 
clean : 
    @echo brisanje objektov 
    rm *.o 
    @echo brisanje izvrsljivega programa 
    rm $(EXE) 

以下是錯誤輸入COMAND時使一個終端,我得到。它清楚地表明「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 .' 

如果我試圖manualy編譯它採用「臂 - 無 - EABI - 爲的Startup.s」它編譯罰款...

我的問題是,爲什麼讓使用cc而不是手臂-none-EABI,作爲?我在這裏錯過了什麼?

所有你的建議後,我設法讓一個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 [email protected] $^ 
%.o : %.S 
    @echo prevajanje ASSEMBLY izvornih datotek... 
    $(AS) -o [email protected] $< 
%.o : %.h 

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

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

當我試圖在其他項目中使用相同的生成文件(項目這我的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可以。謝謝大家。

問候。

回答

5

嘗試使用CC而不是GCC(這是默認生成規則中使用的變量),但在這種情況下,它發現了另一個問題:您的規則被忽略。

什麼是「%h」應該做的?

另外請注意,不執行您的「回聲」命令 - 你的規則不被認爲是另一條線索使組裝

+0

我會將GCC更改爲CC。 %.h應該包含先決條件中的頭文件...我已經閱讀了GNU make教程和目標系統的先決條件,這些都是這樣設置的:「target.o:prereq1.c prereq1.h」所以我按照這樣做了。我還可以包括頭文件嗎? – 71GA 2011-04-11 20:31:13

+0

我也將%h更改爲%.h。 Regards – 71GA 2011-04-11 21:04:41

+0

你忘了「。」以%.h(%h代替)。 您可以使用兩個規則:一個定義動作的「%.o:%.c」,然後是「%.o:%.h」,不需要任何操作作爲簡單的依賴規則 – 2011-04-12 15:36:04

2

你的.o文件將被用於.c文件中的.o規則overwrittent。你沒有結束你的目標文件中的.o試試這個:

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

而且你的裝配規則變爲:

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

你當然可以我們.o_assembly或什麼的。只有使用隱式規則時,對象文件才必須以.o結尾。

+0

我會試試它非常感謝建議。 – 71GA 2011-04-12 10:26:11

+0

我將.o更改爲。所以就像擁塞並試圖讓我的項目,現在我得到一個錯誤:「沒有規則,使目標'startup.So','EXE'需要。停止。」 – 71GA 2011-04-12 10:52:31