【发布时间】:2016-07-19 08:42:51
【问题描述】:
我是 Makefile 的新手,正在尝试用它创建一个 cpp 项目。 现在我只有“hello world”程序(只有 main.cpp 文件)。 尝试使用 make 编译时,我无法停止收到此错误:
g++ -std=c++0x -g -Wall -o sub_game main.o
g++: error: main.o: No such file or directory
g++: fatal error: no input files
compilation terminated.
Makefile:38: recipe for target 'sub_game' failed
make: *** [sub_game] Error 4
我不明白我做错了什么,感谢您的帮助。
这是 Makefile:
# the compiler: gcc for C program, define as g++ for C++
CC = g++
# compiler flags:
# -g adds debugging information to the executable file
# -Wall turns on most, but not all, compiler warnings
CXXLAGS = -std=c++0x -g -Wall
# the build target executable:
TARGET = sub_game
# define any libraries to link into executable:
LIBS = -lpthread -lgtest
# define the C source files
SRCS = ../src
# define the C object files
#
# This uses Suffix Replacement within a macro:
# $(name:string1=string2)
# For each word in 'name' replace 'string1' with 'string2'
# Below we are replacing the suffix .cc of all words in the macro SRCS
# with the .o suffix
#
#OBJ = $(SRCS)/main.cc
OBJ = main.o
# define any directories containing header files other than /usr/include
#
INCLUDES = -I../include
all : $(TARGET)
$(TARGET) : $(OBJ)
$(CC) $(CXXLAGS) -o $(TARGET) $(OBJ)
main.o : $(SRCS)/main.cpp
.PHONY : clean
clean :
rm $(TARGET) $(OBJ)
先谢谢你了。
【问题讨论】:
-
好像没问题。尝试在 main.o 规则下编写编译命令。
-
我添加了这条规则并且它起作用了:g++ -c $(SRCS)/main.cpp 这就是我需要添加的全部内容吗?
-
我想它现在可以工作了......顺便说一句,使用 CXXFLAGS(不是 CXXLAGS)