2017-08-11 16 views
1
は、誰もが重複としてこれをマークする前に

、私は無駄にこれらの質問を見てきましたとしましょうMakefile, find sources in src directory tree and compile to .o in build file
C++ Makefile. .o in different subdirectories
Makefile: Compiling from directory to another directorySRCでの.cpp /ビルド/に.oの出力をコンパイルする方法

私が正しく構築するために、このルールを取得することができません、私がしようと、これらのソリューションの、どんなに:

私はSRC、ビンを持っている、と私のプロジェクトフォルダでmain.cppに、reminder.hpp、およびコントローラ内のフォルダ を構築し、私のプロジェクトフォルダで

CPPFLAGS = -c -Wall -g \ 
     -I/usr/include/glib-2.0 \ 
     -I/usr/lib/x86_64-linux-gnu/glib-2.0/include \ 
     -I/user/include/gdk-pixbux-2.0 \ 
     -Iinclude 
LFLAGS = -Wall -g 
LIB = -lnotify 
SRC_DIR = src 
INCL_DIR = include 
OBJ_DIR = build 
TARGET_DIR = bin 
SRC := $(subst $(SRC_DIR)/,,$(wildcard src/*.cpp)) 
INCL := $(subst $(INCL_DIR)/,,$(wildcard include/*.hpp)) 
OBJ := $(SRC:.cpp=.o) 
TARGET = reminders 
CC = g++ 

.PHONY: clean 

$(TARGET_DIR)/$(TARGET): $(OBJ_DIR)/$(OBJ) 
     $(CC) $(LFLAGS) -o [email protected] $^ $(LIB) 
     @echo Build successful 

$(OBJ_DIR)/$(OBJ): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp 
     $(CC) $(CPPFLAGS) -o [email protected] $< 

clean: 
     rm -rf *.o build/* bin/* *~ 

$(OBJ_DIR)/$(OBJ): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp 
    $(CC) $(CPPFLAGS) -o [email protected] $< 

はここでフルメイクファイルです。 cpp。 これは私がmakeを実行したときに、私が得るものです:

Makefile:24: target 'main.o' doesn't match the target pattern 
g++ -c -Wall -g -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/user/include/gdk-pixbux-2.0 -Iinclude -o mai 
g++: fatal error: no input files 
compilation terminated. 
Makefile:25: recipe for target 'main.o' failed 
make: *** [main.o] Error 1 
shell returned 2 

答えて

3

は、私にはよく... すべて ...テストの習慣を学ぶことをアドバイス。

があなたのソースディレクトリは、あなたのメイクファイルで今

blue.cpp main.cpp red.cpp 

が含まれているとし、これを試してみてください。

$(info $(OBJ_DIR)/$(OBJ)) 

これが生成します。

obj/blue.o main.o red.o 

のAckを!今あなたはあなたのルールが失敗する理由を知っています。そのようにプレフィックスを追加することはできません。パターンは$(OBJ_DIR)/%.oですが、ターゲットmain.oはパターンと一致しません。

これを試してみてください:

SRC := $(wildcard $(SRC_DIR)/*.cpp) # src/blue.cpp ... 
OBJ := $(patsubst $(SRC_DIR)/%.cpp, $(OBJ_DIR)/%.o, $(SRC)) # obj/blue.o ... 

$(TARGET_DIR)/$(TARGET): $(OBJ) 
    $(CC) $(LFLAGS) -o [email protected] $^ $(LIB) 
    @echo Build successful 

$(OBJ): $(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp 
    $(CC) $(CPPFLAGS) -o [email protected] $< 
関連する問題