white space and makefile

一笑奈何 提交于 2019-12-10 16:50:29

问题


Im trying to compile a project with white space into path directories. here you have my 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)

When i launch "make re", i have this result :

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

i don't succeed to fix this problem of the directory with white space. The name of the directory is Files cpp.

Anyone can help me plz ?

edit : i try with one \ and it's not working. i had this result :

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

回答1:


As Tio Pepe suggested, you should just just create a symlink to that directory ln -s Files\ cpp Files_cpp (and any other file with spaces) and use Files_cpp in your Makefile and you will save countless hours of trying to figure out how make handles spaces.

Yes, those double backslashed are correct but later use of $(SRCS:.cpp=.o) and $(OBJS) will only screw the paths without any regards to spaces. As this page points out, you would have to decode and encode the paths - I've tried doing so in a simple example failing miserably every time, so let me tell you - you're much better off just not having to deal with spaces in paths at all. Rename the directory or use a symlink without spaces.




回答2:


Use the 8.3 file name instead Use dir /x to see what it is




回答3:


I am super close to solving the question. I have all my OBJFILES, SRCFILES, etc. properly formed in a fashion like this. "/home/latency/projects/Function Pointers/depends" ".depends"

When I go to create a build rule, is where I am running into problems.

-include $(BINPATH)/$(DEPSFILE)

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

I am not sure what to really do at this point. But I am down to fixing a few build rules and I got this thing to work universally with spaces in filenames & dirs.



来源:https://stackoverflow.com/questions/9514920/white-space-and-makefile

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!