我是Makefile的新手,试图用它创建一个cpp项目。 现在我只有“hello world”程序(只有main.cpp文件)。 我不能停止想用make编译时收到此错误:出错:“g ++:error:main.o:没有这样的文件或目录”
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规则的命令。 – EFenix
我添加了这个规则,它的工作: g ++ -c $(SRCS)/main.cpp 这就是我需要添加的所有东西吗? – dorash
我想现在可以...顺便说一下,使用CXXFLAGS(不是CXXLAGS) – EFenix