Shell / Makefile 链接器
我已经下载了 makefile,并在 xcode 中使用 C/C++ 代码运行它。
它可以工作并输出信息(在控制台模式下),但是当我在做应用程序(使用 GUI)时,它说:
**make: avr-gcc: No such file or directory make: *** [main.o] Error 1**
我像这样运行它:
snprintf(cmd, sizeof(cmd), "make -C \"%s/System/\" flash", path);
等等。但是编译器不会生成/导出 (.o ) 文件,因此链接器无法找到它们。
######### AVR Project Makefile Template #########
###### ######
###### Copyright (C) 2003-2005,Pat Deegan, ######
###### Psychogenic Inc ######
###### All Rights Reserved ######
###### ######
###### You are free to use this code as part ######
###### of your own applications provided ######
###### you keep this copyright notice intact ######
###### and acknowledge its authorship with ######
###### the words: ######
###### ######
###### "Contains software by Pat Deegan of ######
###### Psychogenic Inc (www.psychogenic.com)" ######
###### ######
###### If you use it as part of a web site ######
###### please include a link to our site, ######
###### http://electrons.psychogenic.com or ######
###### http://www.psychogenic.com ######
###### ######
####################################################
##### This Makefile will make compiling Atmel AVR
##### micro controller projects simple with Linux
##### or other Unix workstations and the AVR-GCC
##### tools.
#####
##### It supports C, C++ and Assembly source files.
#####
##### Customize the values as indicated below and :
##### make
##### make disasm
##### make stats
##### make hex
##### make writeflash
##### make gdbinit
##### or make clean
#####
##### See the http://electrons.psychogenic.com/
##### website for detailed instructions
####################################################
##### #####
##### Configuration #####
##### #####
##### Customize the values in this section for #####
##### your project. MCU, PROJECTNAME and #####
##### PRJSRC must be setup for all projects, #####
##### the remaining variables are only #####
##### relevant to those needing additional #####
##### include dirs or libraries and those #####
##### who wish to use the avrdude programmer #####
##### #####
##### See http://electrons.psychogenic.com/ #####
##### for further details. #####
##### #####
####################################################
##### Target Specific Details #####
##### Customize these for your project #####
# Name of target controller
# (e.g. 'at90s8515', see the available avr-gcc mmcu
# options for possible values)
MCU=atmega8
# id to use with programmer
# default: PROGRAMMER_MCU=$(MCU)
# In case the programer used, e.g avrdude, doesn't
# accept the same MCU name as avr-gcc (for example
# for ATmega8s, avr-gcc expects 'atmega8' and
# avrdude requires 'm8')
PROGRAMMER_MCU=m8
# Name of our project
# (use a single word, e.g. 'myproject')
PROJECTNAME=myproject
# Source files
# List C/C++/Assembly source files:
# (list all files to compile, e.g. 'a.c b.cpp as.S'):
# Use .cc, .cpp or .C suffix for C++ files, use .S
# (NOT .s !!!) for assembly source code files.
PRJSRC=main.c myclass.cpp lowlevelstuff.S
# additional includes (e.g. -I/path/to/mydir)
INC=-I/path/to/include
# libraries to link in (e.g. -lmylib)
LIBS=
# Optimization level,
# use s (size opt), 1, 2, 3 or 0 (off)
OPTLEVEL=s
##### AVR Dude 'writeflash' options #####
##### If you are using the avrdude program
##### (http://www.bsdhome.com/avrdude/) to write
##### to the MCU, you can set the following config
##### options and use 'make writeflash' to program
##### the device.
# programmer id--check the avrdude for complete list
# of available opts. These should include stk500,
# avr910, avrisp, bsd, pony and more. Set this to
# one of the valid "-c PROGRAMMER-ID" values
# described in the avrdude info page.
#
AVRDUDE_PROGRAMMERID=stk500
# port--serial or parallel port to which your
# hardware programmer is attached
#
AVRDUDE_PORT=/dev/ttyS1
####################################################
##### Config Done #####
##### #####
##### You shouldn't need to edit anything #####
##### below to use the makefile but may wish #####
##### to override a few of the flags #####
##### nonetheless #####
##### #####
####################################################
##### Flags ####
# HEXFORMAT -- format for .hex file output
HEXFORMAT=ihex
# compiler
CFLAGS=-I. $(INC) -g -mmcu=$(MCU) -O$(OPTLEVEL) \
-fpack-struct -fshort-enums \
-funsigned-bitfields -funsigned-char \
-Wall -Wstrict-prototypes \
-Wa,-ahlms=$(firstword \
$(filter %.lst, $(<:.c=.lst)))
# c++ specific flags
CPPFLAGS=-fno-exceptions \
-Wa,-ahlms=$(firstword \
$(filter %.lst, $(<:.cpp=.lst))\
$(filter %.lst, $(<:.cc=.lst)) \
$(filter %.lst, $(<:.C=.lst)))
# assembler
ASMFLAGS =-I. $(INC) -mmcu=$(MCU) \
-x assembler-with-cpp \
-Wa,-gstabs,-ahlms=$(firstword \
$(<:.S=.lst) $(<.s=.lst))
# linker
LDFLAGS=-Wl,-Map,$(TRG).map -mmcu=$(MCU) \
-lm $(LIBS)
##### executables ####
CC=avr-gcc
OBJCOPY=avr-objcopy
OBJDUMP=avr-objdump
SIZE=avr-size
AVRDUDE=avrdude
REMOVE=rm -f
##### automatic target names ####
TRG=$(PROJECTNAME).out
DUMPTRG=$(PROJECTNAME).s
HEXROMTRG=$(PROJECTNAME).hex
HEXTRG=$(HEXROMTRG) $(PROJECTNAME).ee.hex
GDBINITFILE=gdbinit-$(PROJECTNAME)
# Define all object files.
# Start by splitting source files by type
# C++
CPPFILES=$(filter %.cpp, $(PRJSRC))
CCFILES=$(filter %.cc, $(PRJSRC))
BIGCFILES=$(filter %.C, $(PRJSRC))
# C
CFILES=$(filter %.c, $(PRJSRC))
# Assembly
ASMFILES=$(filter %.S, $(PRJSRC))
# List all object files we need to create
OBJDEPS=$(CFILES:.c=.o) \
$(CPPFILES:.cpp=.o)\
$(BIGCFILES:.C=.o) \
$(CCFILES:.cc=.o) \
$(ASMFILES:.S=.o)
# Define all lst files.
LST=$(filter %.lst, $(OBJDEPS:.o=.lst))
# All the possible generated assembly
# files (.s files)
GENASMFILES=$(filter %.s, $(OBJDEPS:.o=.s))
.SUFFIXES : .c .cc .cpp .C .o .out .s .S \
.hex .ee.hex .h .hh .hpp
.PHONY: writeflash clean stats gdbinit stats
# Make targets:
# all, disasm, stats, hex, writeflash/install, clean
all: $(TRG)
disasm: $(DUMPTRG) stats
stats: $(TRG)
$(OBJDUMP) -h $(TRG)
$(SIZE) $(TRG)
hex: $(HEXTRG)
writeflash: hex
$(AVRDUDE) -c $(AVRDUDE_PROGRAMMERID) \
-p $(PROGRAMMER_MCU) -P $(AVRDUDE_PORT) -e \
-U flash:w:$(HEXROMTRG)
install: writeflash
$(DUMPTRG): $(TRG)
$(OBJDUMP) -S $< > $@
$(TRG): $(OBJDEPS)
$(CC) $(LDFLAGS) -o $(TRG) $(OBJDEPS)
#### Generating assembly ####
# asm from C
%.s: %.c
$(CC) -S $(CFLAGS) $< -o $@
# asm from (hand coded) asm
%.s: %.S
$(CC) -S $(ASMFLAGS) $< > $@
# asm from C++
.cpp.s .cc.s .C.s :
$(CC) -S $(CFLAGS) $(CPPFLAGS) $< -o $@
#### Generating object files ####
# object from C
.c.o:
$(CC) $(CFLAGS) -c $< -o $@
# object from C++ (.cc, .cpp, .C files)
.cc.o .cpp.o .C.o :
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
# object from asm
.S.o :
$(CC) $(ASMFLAGS) -c $< -o $@
#### Generating hex files ####
# hex files from elf
##### Generating a gdb initialisation file #####
.out.hex:
$(OBJCOPY) -j .text \
-j .data \
-O $(HEXFORMAT) $< $@
.out.ee.hex:
$(OBJCOPY) -j .eeprom \
--change-section-lma .eeprom=0 \
-O $(HEXFORMAT) $< $@
##### Generating a gdb initialisation file #####
##### Use by launching simulavr and avr-gdb: #####
##### avr-gdb -x gdbinit-myproject #####
gdbinit: $(GDBINITFILE)
$(GDBINITFILE): $(TRG)
@echo "file $(TRG)" > $(GDBINITFILE)
@echo "target remote localhost:1212" \
>> $(GDBINITFILE)
@echo "load" >> $(GDBINITFILE)
@echo "break main" >> $(GDBINITFILE)
@echo "continue" >> $(GDBINITFILE)
@echo
@echo "Use 'avr-gdb -x $(GDBINITFILE)'"
#### Cleanup ####
clean:
$(REMOVE) $(TRG) $(TRG).map $(DUMPTRG)
$(REMOVE) $(OBJDEPS)
$(REMOVE) $(LST) $(GDBINITFILE)
$(REMOVE) $(GENASMFILES)
$(REMOVE) $(HEXTRG)
##### EOF #####
I have downloaded the makefile and I'm running it with C/C++ code in xcode.
It works and output the information (in console mode), but when I'm doing app (with GUI) it says:
**make: avr-gcc: No such file or directory make: *** [main.o] Error 1**
I'm running it like this:
snprintf(cmd, sizeof(cmd), "make -C \"%s/System/\" flash", path);
etc.. but the compiler dosen't generate / export the (.o) files, so the linker fails to find them.
######### AVR Project Makefile Template #########
###### ######
###### Copyright (C) 2003-2005,Pat Deegan, ######
###### Psychogenic Inc ######
###### All Rights Reserved ######
###### ######
###### You are free to use this code as part ######
###### of your own applications provided ######
###### you keep this copyright notice intact ######
###### and acknowledge its authorship with ######
###### the words: ######
###### ######
###### "Contains software by Pat Deegan of ######
###### Psychogenic Inc (www.psychogenic.com)" ######
###### ######
###### If you use it as part of a web site ######
###### please include a link to our site, ######
###### http://electrons.psychogenic.com or ######
###### http://www.psychogenic.com ######
###### ######
####################################################
##### This Makefile will make compiling Atmel AVR
##### micro controller projects simple with Linux
##### or other Unix workstations and the AVR-GCC
##### tools.
#####
##### It supports C, C++ and Assembly source files.
#####
##### Customize the values as indicated below and :
##### make
##### make disasm
##### make stats
##### make hex
##### make writeflash
##### make gdbinit
##### or make clean
#####
##### See the http://electrons.psychogenic.com/
##### website for detailed instructions
####################################################
##### #####
##### Configuration #####
##### #####
##### Customize the values in this section for #####
##### your project. MCU, PROJECTNAME and #####
##### PRJSRC must be setup for all projects, #####
##### the remaining variables are only #####
##### relevant to those needing additional #####
##### include dirs or libraries and those #####
##### who wish to use the avrdude programmer #####
##### #####
##### See http://electrons.psychogenic.com/ #####
##### for further details. #####
##### #####
####################################################
##### Target Specific Details #####
##### Customize these for your project #####
# Name of target controller
# (e.g. 'at90s8515', see the available avr-gcc mmcu
# options for possible values)
MCU=atmega8
# id to use with programmer
# default: PROGRAMMER_MCU=$(MCU)
# In case the programer used, e.g avrdude, doesn't
# accept the same MCU name as avr-gcc (for example
# for ATmega8s, avr-gcc expects 'atmega8' and
# avrdude requires 'm8')
PROGRAMMER_MCU=m8
# Name of our project
# (use a single word, e.g. 'myproject')
PROJECTNAME=myproject
# Source files
# List C/C++/Assembly source files:
# (list all files to compile, e.g. 'a.c b.cpp as.S'):
# Use .cc, .cpp or .C suffix for C++ files, use .S
# (NOT .s !!!) for assembly source code files.
PRJSRC=main.c myclass.cpp lowlevelstuff.S
# additional includes (e.g. -I/path/to/mydir)
INC=-I/path/to/include
# libraries to link in (e.g. -lmylib)
LIBS=
# Optimization level,
# use s (size opt), 1, 2, 3 or 0 (off)
OPTLEVEL=s
##### AVR Dude 'writeflash' options #####
##### If you are using the avrdude program
##### (http://www.bsdhome.com/avrdude/) to write
##### to the MCU, you can set the following config
##### options and use 'make writeflash' to program
##### the device.
# programmer id--check the avrdude for complete list
# of available opts. These should include stk500,
# avr910, avrisp, bsd, pony and more. Set this to
# one of the valid "-c PROGRAMMER-ID" values
# described in the avrdude info page.
#
AVRDUDE_PROGRAMMERID=stk500
# port--serial or parallel port to which your
# hardware programmer is attached
#
AVRDUDE_PORT=/dev/ttyS1
####################################################
##### Config Done #####
##### #####
##### You shouldn't need to edit anything #####
##### below to use the makefile but may wish #####
##### to override a few of the flags #####
##### nonetheless #####
##### #####
####################################################
##### Flags ####
# HEXFORMAT -- format for .hex file output
HEXFORMAT=ihex
# compiler
CFLAGS=-I. $(INC) -g -mmcu=$(MCU) -O$(OPTLEVEL) \
-fpack-struct -fshort-enums \
-funsigned-bitfields -funsigned-char \
-Wall -Wstrict-prototypes \
-Wa,-ahlms=$(firstword \
$(filter %.lst, $(<:.c=.lst)))
# c++ specific flags
CPPFLAGS=-fno-exceptions \
-Wa,-ahlms=$(firstword \
$(filter %.lst, $(<:.cpp=.lst))\
$(filter %.lst, $(<:.cc=.lst)) \
$(filter %.lst, $(<:.C=.lst)))
# assembler
ASMFLAGS =-I. $(INC) -mmcu=$(MCU) \
-x assembler-with-cpp \
-Wa,-gstabs,-ahlms=$(firstword \
$(<:.S=.lst) $(<.s=.lst))
# linker
LDFLAGS=-Wl,-Map,$(TRG).map -mmcu=$(MCU) \
-lm $(LIBS)
##### executables ####
CC=avr-gcc
OBJCOPY=avr-objcopy
OBJDUMP=avr-objdump
SIZE=avr-size
AVRDUDE=avrdude
REMOVE=rm -f
##### automatic target names ####
TRG=$(PROJECTNAME).out
DUMPTRG=$(PROJECTNAME).s
HEXROMTRG=$(PROJECTNAME).hex
HEXTRG=$(HEXROMTRG) $(PROJECTNAME).ee.hex
GDBINITFILE=gdbinit-$(PROJECTNAME)
# Define all object files.
# Start by splitting source files by type
# C++
CPPFILES=$(filter %.cpp, $(PRJSRC))
CCFILES=$(filter %.cc, $(PRJSRC))
BIGCFILES=$(filter %.C, $(PRJSRC))
# C
CFILES=$(filter %.c, $(PRJSRC))
# Assembly
ASMFILES=$(filter %.S, $(PRJSRC))
# List all object files we need to create
OBJDEPS=$(CFILES:.c=.o) \
$(CPPFILES:.cpp=.o)\
$(BIGCFILES:.C=.o) \
$(CCFILES:.cc=.o) \
$(ASMFILES:.S=.o)
# Define all lst files.
LST=$(filter %.lst, $(OBJDEPS:.o=.lst))
# All the possible generated assembly
# files (.s files)
GENASMFILES=$(filter %.s, $(OBJDEPS:.o=.s))
.SUFFIXES : .c .cc .cpp .C .o .out .s .S \
.hex .ee.hex .h .hh .hpp
.PHONY: writeflash clean stats gdbinit stats
# Make targets:
# all, disasm, stats, hex, writeflash/install, clean
all: $(TRG)
disasm: $(DUMPTRG) stats
stats: $(TRG)
$(OBJDUMP) -h $(TRG)
$(SIZE) $(TRG)
hex: $(HEXTRG)
writeflash: hex
$(AVRDUDE) -c $(AVRDUDE_PROGRAMMERID) \
-p $(PROGRAMMER_MCU) -P $(AVRDUDE_PORT) -e \
-U flash:w:$(HEXROMTRG)
install: writeflash
$(DUMPTRG): $(TRG)
$(OBJDUMP) -S lt; > $@
$(TRG): $(OBJDEPS)
$(CC) $(LDFLAGS) -o $(TRG) $(OBJDEPS)
#### Generating assembly ####
# asm from C
%.s: %.c
$(CC) -S $(CFLAGS) lt; -o $@
# asm from (hand coded) asm
%.s: %.S
$(CC) -S $(ASMFLAGS) lt; > $@
# asm from C++
.cpp.s .cc.s .C.s :
$(CC) -S $(CFLAGS) $(CPPFLAGS) lt; -o $@
#### Generating object files ####
# object from C
.c.o:
$(CC) $(CFLAGS) -c lt; -o $@
# object from C++ (.cc, .cpp, .C files)
.cc.o .cpp.o .C.o :
$(CC) $(CFLAGS) $(CPPFLAGS) -c lt; -o $@
# object from asm
.S.o :
$(CC) $(ASMFLAGS) -c lt; -o $@
#### Generating hex files ####
# hex files from elf
##### Generating a gdb initialisation file #####
.out.hex:
$(OBJCOPY) -j .text \
-j .data \
-O $(HEXFORMAT) lt; $@
.out.ee.hex:
$(OBJCOPY) -j .eeprom \
--change-section-lma .eeprom=0 \
-O $(HEXFORMAT) lt; $@
##### Generating a gdb initialisation file #####
##### Use by launching simulavr and avr-gdb: #####
##### avr-gdb -x gdbinit-myproject #####
gdbinit: $(GDBINITFILE)
$(GDBINITFILE): $(TRG)
@echo "file $(TRG)" > $(GDBINITFILE)
@echo "target remote localhost:1212" \
>> $(GDBINITFILE)
@echo "load" >> $(GDBINITFILE)
@echo "break main" >> $(GDBINITFILE)
@echo "continue" >> $(GDBINITFILE)
@echo
@echo "Use 'avr-gdb -x $(GDBINITFILE)'"
#### Cleanup ####
clean:
$(REMOVE) $(TRG) $(TRG).map $(DUMPTRG)
$(REMOVE) $(OBJDEPS)
$(REMOVE) $(LST) $(GDBINITFILE)
$(REMOVE) $(GENASMFILES)
$(REMOVE) $(HEXTRG)
##### EOF #####
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误消息,例如
指示以下几项之一
可执行文件
avr-gcc
未安装(正确)和/或 PATH 环境变量不包含保存可执行文件的目录
makefile 调用不正确。
其他
这里有一些可以尝试的事情
当你说“下载了makefile”时,你是下载了全部,还是下载了完整的软件包(avr?) 如果只是makefile,你必须先下载整个软件包才能下载继续。
许多软件包依赖于自动捕获的设置信息或作为环境变量传递来运行 make 文件。
查看软件分发版附带的 .txt(有时为 .doc)文件。查找自述文件或安装。您可能会发现需要运行一组简单的命令来设置环境。很多时候,
这就是你所需要的。
如果你的包中没有这样的指示,那么你需要找到你的 avr-gcc 所在的位置并将其添加到 PATH 中,即
采用返回的路径,去掉结尾的
/avr-gcc 并将其添加到您的 PATH 中,即
如果这不起作用,请编辑您的问题以包含此包源代码的 URL。
error messages like
Indicate 1 of several things
the executable
avr-gcc
is not installed (properly)and/or the PATH env var does not include the directory that holds the executable
the makefile was called incorrectly.
Others
Here are some things to try
When you say "downloaded the makefile", is that all you downloaded, or did you download a complete package (avr?) If just the makefile, you have to download the whole software package first before you can continue.
Many software packages rely on set-up information being captured automatically or passed in as env-vars to running the make file.
Look through the .txt (sometimes .doc) files that come with the software distribution. Look for README or INSTALL. You might find that you need to run a simple set of commands to setup the environment. Very often
is all you need.
If there are no directions like that with your package, then you need to discover where your avr-gcc is located and add that to the PATH, i.e.
Take the path returned by, strip off the ending
/avr-gcc
and add it to your PATH, i.e.If this doesn't work, please edit your question to include a URL to the source code for this package.