Ogre1 study notes 1 - build Ogre project
Confucius said: "Run first and then talk."
This article will introduce the general process of building the Ogre project, and the code part adopts Bootstrap.cpp
the content in the official one.
This article refers to the official English tutorial Setting up an OGRE project , but uses Makefile to build the Ogre project instead of cmake in the English tutorial.
Copy the code and write Makefile
Bootstrap.cpp
The source code of can be found in the Ogre source code, its specific location is in ogre-1.12.6/Samples/Tutorials/Bootstrap.cpp
.
When writing Makefile, there are the following points to note:
- Several additional library files of Ogre need to be added when linking.
Here you need to add 4 libraries such asOgreMain
,OgreBites
,OgreRTShaderSystem
and , so you need to add them as parameters.zzip
-lOgreMain -lOgreBites -lOgreRTShaderSystem -lzzip
- The path that needs to be included
zzip
.
zzip
It is a library file generated when compiling and installing the Ogre source code. Its path isogre-1.12.6/build/Dependencies/lib
, so it needs to be added during compilation-L/home/username/Documents/ogre-1.12.6/build/Dependencies/lib
. Here/home/username/Documents/
is the folder where the Ogre source code is located. - The header file path needs to be added.
Bootstrap.cpp
There are 3 directories where the required header files are located:/usr/include/OGRE/
,/usr/include/OGRE/Bites/
and , so they need to be added as parameters/usr/include/OGRE/RTShaderSystem/
when compiling .-I/usr/include/OGRE/ -I/usr/include/OGRE/Bites/ -I/usr/include/OGRE/RTShaderSystem/
- You need to add rpath
becausezzip
the directory where it is located is not a standard location, so you need to add it-rpath
, otherwise there will be a problem that the compilation is successful but the runtime reports an error. So it needs to be added as a parameter at compile time-Wl,-rpath /home/username/Documents/ogre-1.12.6/build/Dependencies/lib
.
/usr/share/OGRE/
In addition, you also need to resources.cfg
copy to the current folder in order to avoid Sinbad.mesh
errors not found.
run code
The complete Makefile looks like this:
CXX = g++
CXXFLAGS = -std=c++17 -g -Wall
LIBS = -lOgreMain -lOgreBites -lOgreRTShaderSystem -lzzip
LIB_PATH = -L/home/username/Documents/ogre-1.12.6/build/Dependencies/lib
RPATH = -Wl,-rpath /home/username/Documents/ogre-1.12.6/build/Dependencies/lib
INCLUDE = -I/usr/include/OGRE/ -I/usr/include/OGRE/Bites/ -I/usr/include/OGRE/RTShaderSystem/
TAR = Bootstrap
EXT =
$(TAR)$(EXT): $(TAR).cpp
$(CXX) $< -o $@ $(CXXFLAGS) $(RPATH) $(LIBS) $(LIB_PATH) $(INCLUDE)
clean:
-rm $(TAR)$(EXT)
At this point, the current folder should look like this:
.
├── Bootstrap.cpp
├── Makefile
└── resources.cfg
Run the code:
make
./Bootstrap
Running result: Press the button
on this screen to exit.Esc