当我为EXTRAINCDIRS (在Makefile中,遵循WINAVR提供的示例)提供一个不带空格的路径时,编译器能够找到我的头文件,但是当我使用一个包含空格(用引号括起来,作为Makefile中的注释)的路径时,它会引发:error: No such file or directory。
"d:/dev/avr/atmega/shared/" # will search files in this dir
"d:/dev/avr/atmega/sha ed/" # will not search this dir for files我是说,评论说:
# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.你知道如何让WINAVR正确处理这个问题吗?
我在Windows XP上使用程序员记事本(WINAVR)。以下是命令行命令:
avr-g++ -c -mmcu=atmega328p -I. -gdwarf-2 -DF_CPU=UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -Wa,-adhlns=./main.lst -I"d:/dev/avr/atmega/shared/" -I"d:/dev/avr/atmega/sha -Ied/" -std=gnu99 -MMD -MP -MF .dep/main.o.d main.c -o main.o发布于 2012-05-26 22:38:45
发生的情况是,我猜在makefile中的其他地方有一行代码,它的作用类似于:
INCLUDES = $(addprefix -I, $(INCDIRS))当发生这种情况时,addprefix将$(INCDIRS)变量中的任何空格视为下一个变量的分隔符,并将-I添加到其中。您可以做的是使用一个特殊的空格字符,比如'\‘,然后在生成命令之前,调用一个替换函数来重新替换空格。类似于下面的示例:
SPACE = \\
INCDIRS = /home/posey/test$(SPACE)dir
INCLUDES = $(addprefix -I, $(INCDIRS))
REAL_INCLUDES = $(subst $(SPACE), ,$(INCLUDES))
.PHONY : all
all:
$(info $(REAL_INCLUDES))如果这没有意义,你可以发布整个makefile,我们可以向你展示到底发生了什么。一旦将空格替换回变量中,就不能在不发生相同行为的情况下,通过任何使用空格分隔符的make函数来运行它。
https://stackoverflow.com/questions/10762766
复制相似问题