【问题标题】:white space and makefile空白和生成文件
【发布时间】:2012-03-19 20:55:00
【问题描述】:

我正在尝试将带有空格的项目编译到路径目录中。 这里有我的 Makefile :

NAME    =       ./Release/Online_pricer

SRCS    =       ./Online_pricer/main.cpp                        \
                ./Online_pricer/Currency.cpp                    \
                ./Online_pricer/Curve.cpp                       \
                ./Online_pricer/Environment.cpp                 \
                ./Online_pricer/My_convert.cpp                  \
                ./Online_pricer/My_exception.cpp                \
                ./Online_pricer/ParserTab.cpp                   \
                ./Online_pricer/Spot.cpp                        \
                ./Online_pricer/Volatility.cpp                  \
                ./Online_pricer/VolatilityCapFloor.cpp          \
                ./Online_pricer/VolatilitySwaption.cpp          \
                ../Files\\ cpp/Functions.cpp                    \
                ../Files\\ cpp/UtilitiesWeb.cpp

#####################################################                                          

OBJS                    =       $(SRCS:.cpp=.o)
CC                      =       g++
RM                      =       rm -f
CFLAGS                  =       -g -W -Wall -Werror
INCL                    =       ../Files\ .h/

#####################################################                                          

$(NAME) :       $(OBJS)
        @$(CC) $(OBJS) -I$(INCL) $(LIB) -o $(NAME)
        @printf "\n \033[33m[Message]\033[39m Compilation under Linux done\n"

.cpp.o  :
        @$(CC) -I$(INCL) $(CFLAGS) -c $< -o $@
        @printf " \033[34m[Compilation]\033[39m %s\n" $<

re      :       fclean all

all     :       $(NAME)

clean   :
        @$(RM) *~ $(OBJS)
        @printf " \033[31m[Delete] \033[39m%s\n" $(OBJS)

fclean  :       clean
        @$(RM) $(NAME)
        @printf "\n \033[31m[Delete] \033[39m%s\n" $(NAME)

当我启动“make re”时,我得到了这个结果:

make: *** No rule to make target `../Files\', needed by `Release/Online_pricer'.  Stop.

我没有成功解决这个带有空格的目录的问题。目录名称为Files cpp

谁能帮帮我?

编辑:我尝试使用一个\,但它不起作用。我有这个结果:

g++: error: ../Files: No such file or directory
g++: error: cpp/Functions.cpp: No such file or directory
g++: error: cpp/Functions.o: No such file or directory
g++: fatal error: no input files
compilation terminated.
make: *** [../Files cpp/Functions.o] Error 4

【问题讨论】:

  • 问题是那里有双反斜杠。使用单个,所以只需 ../Files\ cpp/
  • 尝试在文件后面只加一个反斜杠。
  • 它不适用于一个`\`。我将结果加入了我的问题。
  • 把文件放在双引号里怎么样?喜欢"../Files cpp/Functions.cpp"
  • 与开始时相同的结果:make: *** No rule to make target "../Files', needed by Release/Online_pricer'. Stop.

标签: c++ compilation makefile g++ gnu-make


【解决方案1】:

正如 Tio Pepe 建议的那样,您只需创建指向该目录 ln -s Files\ cpp Files_cpp(以及任何其他带有空格的文件)的符号链接,并在您的 Makefile 中使用 Files_cpp,您将节省无数小时试图弄清楚make 如何处理空格。

是的,那些双反斜杠是正确的,但以后使用 $(SRCS:.cpp=.o)$(OBJS) 只会拧紧路径,而不考虑空格。正如this page 指出的那样,您必须对路径进行解码和编码-我在一个简单的示例中尝试过这样做,每次都惨败,所以让我告诉您-您最好不必处理路径中的空格。重命名目录或使用不带空格的符号链接。

【讨论】:

  • 是的,谢谢。我同意你的看法,我认为这是最好的方法。谢谢你的帮助:)
  • 也许 CMake 可以更好地处理空格。我自己还没有检查过这个工具,但它当然值得一试,即使只是为了摆脱 Makefiles 中那些可怕的有意义的标签。
  • 甚至 make 的原作者也同意,回想起来,TAB 是一个糟糕的选择。在 GNU make 3.82 中,您可以重新定义“配方介绍字符”并使其与 TAB 不同。当然,这会导致您的 makefile 与任何其他版本的 make 或 3.82 之前的 GNU make 不兼容。
【解决方案2】:

改用 8.3 文件名 使用 dir /x 查看它是什么

【讨论】:

    【解决方案3】:

    我非常接近解决这个问题。我的所有 OBJFILES、SRCFILES 等都以这样的方式正确形成。 "/home/latency/projects/函数指针/依赖" ".depends"

    当我去创建构建规则时,我遇到了问题。

    -包括 $(BINPATH)/$(DEPSFILE)

    make: *** No rule to make target `\"/home/latency/projects/Function', needed by `/home/latency/projects/Function'.  Stop.
    

    我不确定此时该做什么。 但是我正在修复一些构建规则,并且我让这个东西可以普遍使用文件名和目录中的空格。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-12-06
      • 2013-07-16
      • 1970-01-01
      • 1970-01-01
      • 2011-08-21
      • 2019-08-08
      • 1970-01-01
      • 2012-09-13
      相关资源
      最近更新 更多