質問内容
以下のエラーなのですが単純にパスを間違えているだけに思えるのですがなぜかコンパイルが通りませんこれはなぜでしょうか?
Makefileで指定しているのですがなぜでしょうか?すべての最初から再ビルドしても同じエラー出ます名前空間を分けているのですがファイル名が同じなのでなんか怪しいComponent.hpp
について下記のようにいろいろ調べましたが原因がわかりません
実現したいこと
:~/program/project/engine/test$ make
を実行すると以下のエラーが発生するが原因と対処方法を知りたい
エラー
:~/program/project/engine/test$ make g++ -c -MMD -MP src/Main.cpp -o obj/Main.o -I include -I ../include In file included from ../include/Engine.hpp:10, from src/Main.cpp:6: ../include/Component.hpp:4:10: fatal error: Core.hpp: そのようなファイルやディレクトリはありません 4 | #include <Core.hpp> | ^~~~~~~~~~ compilation terminated. make: *** [Makefile:22: obj/Main.o] エラー 1
環境
OS ubuntu
言語 C++ 14
コンパイラ g++
make使用
状況
core
ディレクトリはlibcore.a
を生成してengine
ディレクトリもlibEngine.a
を生成しますそしてengine
ディレクトリの中のtest
ディレクトリ内で実行ファイルを生成している複数のプロジェクトが存在しています
ディレクトリ構成
terminal
1$ tree -L 3 2. 3├── README.md 4├── core 5│ ├── Doxyfile 6│ ├── Makefile 7│ ├── bin 8│ ├── doc 9│ ├── include 10│ │ ├── Camera.hpp 11│ │ ├── Component.hpp 12│ │ ├── Context.hpp 13│ │ ├── Core.hpp 14│ │ ├── SpriteRenderer.hpp 15│ │ ├── Transform.hpp 16│ │ └── imgui 17│ ├── obj 18│ ├── script 19│ │ └── all_build.sh 20│ ├── src 21│ │ ├── Camera.cpp 22│ │ ├── Component.cpp 23│ │ ├── Context.cpp 24│ │ ├── SpriteRenderer.cpp 25│ │ ├── Transform.cpp 26│ │ └── imgui 27│ └── test 28│ ├── Makefile 29│ ├── bin 30│ ├── include 31│ ├── obj 32│ └── src 33├── engine 34│ ├── Doxyfile 35│ ├── Makefile 36│ ├── bin 37│ │ └── libEngine.a 38│ ├── doc 39│ ├── include 40│ │ ├── Component.hpp 41│ │ ├── Engine.hpp 42│ │ ├── その他は省略 43│ │ └── imgui 44│ ├── obj 45│ ├── src 46│ │ ├── Component.cpp 47│ │ ├── その他は省略 48│ │ └── WorldManager.cpp 49│ └── test 50│ ├── Makefile 51│ ├── bin 52│ ├── imgui.ini 53│ ├── include 54│ ├── obj 55│ └── src 56省略
Core.hppの場所を確認
terminal
1:~/program/project/core/include$ ls 2Camera.hpp Component.hpp Context.hpp Core.hpp SpriteRenderer.hpp Transform.hpp imgui
EngineのComponent.hppの場所を確認
terminal
1:~/program/project/engine/include$ ls 2Archetype.hpp Chunk.hpp Component.hpp Engine.hpp EntityManager.hpp Window.hpp WorldManager.hpp 3ArchetypeManager.hpp ChunkManager.hpp ComponentManager.hpp Entity.hpp System.hpp World.hpp imgui
core/include/Component.hpp のインクルードガード
cpp
1#ifndef ___CORE___COMPONENT_HPP___ 2#define ___CORE___COMPONENT_HPP___ 3省略 4#endif
engine/include/Component.hpp のインクルードガード
cpp
1#ifndef ___COMPONENT_HPP___ 2#define ___COMPONENT_HPP___ 3省略 4#endif
:~/program/project/engine/test パスのMakefile
Makefile
1PRG := program 2 3SRC_DIR :=src 4SYSTEM_DIR :=src/system 5HELPER_DIR :=src/helper 6OBJ_DIR :=obj 7DEP_DIR :=obj 8 9DEP :=$(wildcard $(DEP_DIR)/*d) 10SRC :=$(wildcard $(SRC_DIR)/*.cpp) 11SYSTEM :=$(wildcard $(SYSTEM_DIR)/*.cpp) 12HELPER :=$(wildcard $(HELPER_DIR)/*.cpp) 13 14OBJ :=$(addprefix $(OBJ_DIR)/,$(patsubst %.cpp,%.o,$(notdir $(SRC)))) 15OBJ_SYSTEM :=$(addprefix $(OBJ_DIR)/,$(patsubst %.cpp,%.o,$(notdir $(SYSTEM)))) 16OBJ_HELPER :=$(addprefix $(OBJ_DIR)/,$(patsubst %.cpp,%.o,$(notdir $(HELPER)))) 17 18$(PRG): $(OBJ) $(OBJ_SYSTEM) $(OBJ_HELPER) 19 $(CXX) -m64 $^ -o bin/$@ -L ../bin -L ../../core/bin -lEngine -lcore -lglfw -lGLEW -lGL -lX11 -lpthread -lXrandr -lXi -ldl 20 21$(OBJ_DIR)/%.o: src/%.cpp 22 $(CXX) -c -MMD -MP $< -o $@ -I include -I ../include 23-include $(DEP) 24 25$(OBJ_DIR)/%.o: src/system/%.cpp 26 $(CXX) -c -MMD -MP $< -o $@ -I include -I ../include 27-include $(DEP) 28 29$(OBJ_DIR)/%.o: src/helper/%.cpp 30 $(CXX) -c -MMD -MP $< -o $@ -I include -I ../include 31-include $(DEP) 32 33.PHONY: clean 34clean: 35 rm -rf ./$(OBJ_DIR)/*.o *.out ./$(OBJ_DIR)/*.d $(PRG) ./doc/html/ ./doc/latex/
engine/include/Component.hpp ファイル内容
cpp
1#ifndef ___COMPONENT_HPP___ 2#define ___COMPONENT_HPP___ 3 4#include <Core.hpp> 5#include <glm/glm.hpp> 6namespace Engine 7{ 8 class Component : public Core::Component 9 { 10 public: 11 Component(); 12 13 virtual void Update() = 0; 14 void Render(const glm::mat4 view); 15 }; 16} 17#endif
調べたこと
1,core
,engine
,test
の3つのプロジェクトのオブジェクトファイルと.d
ファイルをすべて削除してcore -> engine -> test
の順番に再ビルド
2,Component.hpp
という名前を再確認してファイル名をcore/include
内のComponent.hpp
と同じだめ名前をコピーして貼り付け
3,Core::Component
,Engine::Component
という名前空間で区切っています
4,状況部のようにファイルのパスが正しいか確認
5,インクルードガードですが状況部のようにそれぞれ違います
6, 状況部のMakefile
に一個上の階層であるengine/include
部を指定します
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。