Добрый день, я бегу через учебник, чтобы написать свои собственные мейкфайлы, я нашел учебник здесь:C++ Makefile ошибка - Нет правила, чтобы сделать цели «% .cpp»
http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/
Я знаю, что это Учебник предназначен для C-файлов, но я считаю, что аналогия между C и C++ означают, что мало что влияет на функцию make-файлов (например, я использую g ++, а не gcc). Надеюсь, мое предположение в этом вопросе не является фактором, так как каждый из предыдущих 4 учебников, похоже, работал нормально.
При работе через Makefile 5 в учебнике, я получаю сообщение об ошибке относительно построения объектных файлов из файлов .cpp: Я не могу показаться, чтобы выяснить, почему это происходит
make: *** No rule to make target '%.cpp', needed by 'obj'. Stop.
, очень запутанный и расстраивающий, поскольку я чувствую, что этого не должно происходить. Я включил мой полный Makefile ниже, любая помощь будет принята с благодарностью:
# Example Makefile
# ----------------
# Please remember to turn off the vim option: 'expandtab' so that tabs are
# actually displayed as tabs (do so like this - :set noexpandtab)
#
# This file specifies dependencies, which means that the two c++ files must
# be compiled before the executable is built
# ------------------
# Makefile Constants
# ------------------
# Directory constants
IDIR =../include # Specifies location of include directory
ODIR =obj # Specifies location of object directory
LDIR =../lib # Specifies location of library directory
LIBS=-lm # ?
# Options constants
CC=g++ # Specifies the specific C compiler to use, g++ specifies C++ compiler
CFLAGS=-I$(IDIR) # List of flags to pass to compilation command
# Dependency Constants
DEP_FILES=helloMake.h # Specifies dependency files
DEPS=$(patsubst %,$(IDIR)/%,$(DEP_FILES)) # Specifies path to dependencies and dependency files
# Object constants
OBJ_FILES=helloMake.o helloFunc.o # Specify object files
OBJ=$(patsubst %,$(ODIR)/%,$(OBJ_FILES)) # Specifies path to objects and object files
# -----------
# Compilation
# -----------
# Specify rules to make object files
$(ODIR)/%.o: %.cpp $(DEPS) # Specifies that .o files depend on the .cpp version of the file and the .h files included in the DEPS macro
$(CC) -c -o [email protected] $< $(CFLAGS) # The -c flag says to generate the object file, the -o [email protected] says to put the output of the compilation in the
# file named on the left side of the : the $< is the first item in the dependencies list
# Specify rules to make target executable
helloMake: $(OBJ) # Target : Dependencies
$(CC) -o [email protected] $^ $(CFLAGS) $(LIBS) # This is the actual compilation command
.PHONY: clean # Prevent the make command from attempting to do something with a file named 'clean'
# Specify rules to clean the object files
clean:
rm -f $(ODIR)/*.o *~ core $(INCDIR)/*~ # Removes all compiled object files
Спасибо за ответ, я попробовал Makefile, который вы предложили, но когда я попытаюсь это сделать, теперь я получаю другую ошибку: g ++: ошибка: arm-linux-androideabi: Нет такого файла или каталога – chris2oph
Кажется, ваша настройка компилятора isn Правильно ли, какова ваша среда (ОС, версия компилятора, сделать версию)? – Chnossos
ОС: Linux (с использованием виртуальной машины VMWare vSphere Client) Версия компилятора: g ++ (GCC) 4.9.3 20141101 для GNAT Pro 7.3.1 (20150118) сделать версию: не полностью, что вы имеете в виду tbh! – chris2oph