Ich bin neu in Makefile und versuche, ein cpp-Projekt damit zu erstellen. Jetzt habe ich nur "Hallo Welt" Programm (nur main.cpp Datei). Ich kann nicht aufhören diesen Fehler, wenn sie mit machen, um zu kompilieren versuchen:Fehler machen: "g ++: Fehler: main.o: Keine solche Datei oder Verzeichnis"
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
Ich verstehe nicht, was ich falsch mache, würde Ihre Hilfe zu schätzen wissen.
Dies ist das 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)
Sie in fortgeschrittenen Dank.
Es scheint, um in Ordnung zu sein. Versuchen Sie, einen Befehl für die Kompilierung unter main.o-Regel zu schreiben. – EFenix
Ich habe die Regel hinzugefügt und es funktioniert: g ++ -c $ (SRCS) /main.cpp Ist das alles, was ich hinzufügen muss? – dorash
Ich nehme an, es funktioniert jetzt ... Übrigens, verwenden Sie CXXFLAGS (nicht CXXLAGS) – EFenix