我在OSX上使用make和makefile时遇到问题。
我的错误:
clang: error: no such file or directory: '/Users/sduball/Documents/Programming/Cpp/ncurses_projects/tictactoe/source/main.cpp'
clang: error: no input files
make: *** [main.o] Error
我见过的关于此问题的唯一SO帖子是在手动移动项目后xcode项目未找到文件的情况下实现的。我没有找到与我遇到的这个具体问题有关的任何内容。提前感谢您的帮助。
生成文件
##### VARIABLES #####
CXX = g++
CXXFLAGS = -Wall -g -std=c++14
DIR = ~/Documents/Programming/Cpp/ncurses_projects/tictactoe/
SOURCE = ~/Documents/Programming/Cpp/ncurses_projects/tictactoe/source/
BUILD = ~/Documents/Programming/Cpp/ncurses_projects/tictactoe/build/
##### TARGETS #####
# executable
copy: main.o game.o
$(CXX) $(CXXFLAGS) $(BUILD)main.o $(BUILD)game.o -lncursesw -o $(DIR)copy
# source
main.o: main.cpp game.h
$(CXX) $(CXXFLAGS) -c $(SOURCE)main.cpp -o $(BUILD)main.o
game.o: game.cpp game.h
$(CXX) $(CXXFLAGS) -c $(SOURCE)game.cpp -o $(BUILD)game.o
答案 0 :(得分:0)
您需要使用目标/依赖关系行中的目录变量,而不仅仅是命令行。
##### VARIABLES #####
CXX = g++
CXXFLAGS = -Wall -g -std=c++14
DIR = ~/Documents/Programming/Cpp/ncurses_projects/tictactoe/
SOURCE = ~/Documents/Programming/Cpp/ncurses_projects/tictactoe/source/
BUILD = ~/Documents/Programming/Cpp/ncurses_projects/tictactoe/build/
##### TARGETS #####
# executable
$(DIR)copy: $(BUILD)main.o $(BUILD)game.o
$(CXX) $(CXXFLAGS) $(BUILD)main.o $(BUILD)game.o -lncursesw -o $(DIR)copy
# source
$(BUILD)main.o: $(SOURCE)main.cpp $(SOURCE)game.h
$(CXX) $(CXXFLAGS) -c $(SOURCE)main.cpp -o $(BUILD)main.o
$(BUILD)game.o: $(SOURCE)game.cpp $(SOURCE)game.h
$(CXX) $(CXXFLAGS) -c $(SOURCE)game.cpp -o $(BUILD)game.o
答案 1 :(得分:0)
根据@JonathanLeffler对原始问题的评论,我用DIR =替换了DIR路径。
DIR = ~/Documents/Programming/Cpp/ncurses_projects/tictactoe/
到
DIR = .
这完全解决了这个问题。源代码如下。
生成文件
##### VARIABLES #####
CXX = g++
CXXFLAGS = -Wall -g -std=c++14
DIR = .
SOURCE = $(DIR)/source
BUILD = $(DIR)/build
##### TARGETS #####
# executable
copy: $(BUILD)/main.o $(BUILD)/game.o
$(CXX) $(CXXFLAGS) $(BUILD)/main.o $(BUILD)/game.o -lncursesw -o $(DIR)/copy
# source
main.o: $(SOURCE)/main.cpp $(SOURCE)/game.h
$(CXX) $(CXXFLAGS) -c $(SOUCE)/main.cpp -o $(BUILD)/main.o
game.o: $(SOURCE)/game.cpp $(SOURCE)/game.h
$(CXX) $(CXXFLAGS) -c $(SOURCE)/game.cpp -o $(BUILD)/game.o