以前は、のsrc
フォルダにあるソースファイルを扱うルートディレクトリにmakefileを作成するのに苦労していましたフォルダ。これに続いて、別のフォルダtests
を追加して、どこに.cppファイルを保存するかを考えました。残念ながら私はこれに問題があります。-Makefileの-Iフラグは、ヘッダファイルが見つからない(gtest/gtest.h)
フォルダ構造は次のとおりです。
.
|__makefile
|
|__/src
| |
| |__[regular .cpp files]
|
|__/include
| |
| |__[.h files]
| |
| |__/gtest
| |
| |__gtest.h
|
|__/tests
|
|__test_factorial.cpp
./tests/test_factorial.cpp:
#include "gtest/gtest.h"
#include "factorial.h"
// some tests
メイク:
CC = g++
CFLAGS = -Wall
INCLUDES = -I./include
LIBS = -lgtest -lpthread
SOURCEDIR = ./src/
SRCS = $(shell find ./src/ -name '*.cpp')
SRCS += $(shell find ./tests/ -name '*.cpp')
.PHONY: clean depend
SRCS := $(filter-out ./tests/main_tests.cpp, $(SRCS))
OBJS = $(SRCS:.cpp=.o)
OBJS := $(OBJS:./src%=.%)
release: $(OBJS)
$(CC) $(CFLAGS) -o app $(OBJS) $(LIBS)
VPATH = ./src:./tests
%.o: ./src/%.cpp
$(CC) $(CFLAGS) $(INCLUDES) -c ./src/$*.cpp
%.o: ./tests/%.cpp
$(CC) $(CFLAGS) $(INCLUDES) -c ./tests/$*.cpp
depend: .depend
.depend: $(SRCS)
rm -f ./.depend
$(CC) $(CFLAGS) $(INCLUDES) -MM $^ > ./.depend;
include .depend
私はルートディレクトリからすべてのmake
を実行します/ srcからのファイルはうまくコンパイルされます(私は彼らのためにルートディレクトリにオブジェクトファイルを持っています)buトン私はtestsディレクトリ/から.cppファイルのエラーを取得:重要であるかもしれない
g++ -c -o tests/test_factorial.o tests/test_factorial.cpp
tests/test_factorial.cpp:1:25: fatal error: gtest/gtest.h: No such file or directory
compilation terminated.
<builtin>: recipe for target 'tests/test_factorial.o' failed
make: *** [tests/test_factorial.o] Error 1
何、.dependファイルは、それがすべて権利があるようです:
メイクファイルと間違っている何test_factorial.o: tests/test_factorial.cpp include/gtest/gtest.h \
include/factorial.h
?
<builtin>: recipe for target 'tests/test_factorial.o' failed
何かがメイクファイルのこの部分で間違っていることを示唆している:
%.o: ./src/%.cpp
$(CC) $(CFLAGS) $(INCLUDES) -c ./src/$*.cpp
%.o: ./tests/%.cpp
$(CC) $(CFLAGS) $(INCLUDES) -c ./tests/$*.cpp
それが何をしようとしているのはなぜ私は、エラーのこの断片が信じる
EDIT
./test_factorial.o
ではなく./tests/test_factorial.o
? ./src/*.cppファイルのオブジェクトファイルがルートディレクトリ(つまり、./src/*.o
ではなく./*.o
)に終わることをもう一度強調しましょう。
ため
src/
なし同様のルールを剥ぎ取り、その後のルールを持って、実際のビルド出力が 'に渡されるいかなる' -I'オプションを示していませんg ++ ' –