Praktische Aspekte der Informatik
Moritz Mühlhausen
- Prof. Marcus Magnor
https://graphics.tu-bs.de/teaching/ss19/padi/
der Informatik Moritz Mhlhausen Prof. Marcus Magnor - - PowerPoint PPT Presentation
Praktische Aspekte der Informatik Moritz Mhlhausen Prof. Marcus Magnor https://graphics.tu-bs.de/teaching/ss19/padi/ Make, Libraries, and Debugging make, cmake, libraries, gdb, and IDEs https://graphics.tu-bs.de/teaching/ss19/padi/
Moritz Mühlhausen
https://graphics.tu-bs.de/teaching/ss19/padi/
make, cmake, libraries, gdb, and IDEs
https://graphics.tu-bs.de/teaching/ss19/padi/
Further Reading
http://sslabmcs12.weebly.com/uploads/9/2/2/0/9220774/makefiletutorial.pdf http://www.cmake.org/Wiki/CMake http://www.cs.cmu.edu/~gilpin/tutorial http://qt-project.org
https://graphics.tu-bs.de/teaching/ss19/padi/
Outline
https://graphics.tu-bs.de/teaching/ss19/padi/
Building with Make
https://graphics.tu-bs.de/teaching/ss19/padi/
Building with Make
Makefile
CXX=g++ CXXFLAGS=-I. –g –std=c++11 EXE=worldbuilder $(EXE): main.o Block.o Sphere.o WorldBuilder.o Vector3D.o $(CXX) $(CXXFLAGS) -o $@ $^ main.o: main.cpp WorldBuilder.h WorldObject.h Block.h Sphere.h $(CXX) $(CXXFLAGS) -c $< Block.o: Block.cpp Block.h WorldObject.h Vector3D.h $(CXX) $(CXXFLAGS) -c $< […] Vector3D.o: Vector3D.cpp Vector3D.h $(CXX) $(CXXFLAGS) -c $< clean: rm -f *.o *~ $(EXE)
https://graphics.tu-bs.de/teaching/ss19/padi/
Building with Make
Makefile
CXX=g++ CXXFLAGS=-I. –g –std=c++11 EXE=worldbuilder $(EXE): main.o Block.o Sphere.o WorldBuilder.o Vector3D.o $(CXX) $(CXXFLAGS) -o $@ $^ main.o: main.cpp WorldBuilder.h WorldObject.h Block.h Sphere.h $(CXX) $(CXXFLAGS) -c $< Block.o: Block.cpp Block.h WorldObject.h Vector3D.h $(CXX) $(CXXFLAGS) -c $< […] Vector3D.o: Vector3D.cpp Vector3D.h $(CXX) $(CXXFLAGS) -c $< clean: rm -f *.o *~ $(EXE)
Output value All input values First input value (usually *.cpp)
https://graphics.tu-bs.de/teaching/ss19/padi/
Building with Make
Makefile
CXX=g++ CXXFLAGS=-I. –g –std=c++11 EXE=worldbuilder $(EXE): main.o Block.o Sphere.o WorldBuilder.o Vector3D.o $(CXX) $(CXXFLAGS) -o $@ $^ %.o: %.cpp $(CXX) $(CXXFLAGS) -c $< clean: rm -f *.o *~ $(EXE)
Pro: Easier to read Con: make does not know header dependencies
https://graphics.tu-bs.de/teaching/ss19/padi/
Outline
https://graphics.tu-bs.de/teaching/ss19/padi/
Building with CMake
https://graphics.tu-bs.de/teaching/ss19/padi/
Building with CMake
CMakeLists.txt project(worldbuilder) set(CMAKE_CXX_FLAGS "-g") set(CMAKE_CXX_FLAGS_DEBUG) set(worldbuilder_SOURCES main.cpp Block.cpp Sphere.cpp WorldBuilder.cpp Vector3D.cpp) add_executable(worldbuilder ${worldbuilder_SOURCES})
https://graphics.tu-bs.de/teaching/ss19/padi/
Building with CMake
https://graphics.tu-bs.de/teaching/ss19/padi/
More Cross-Platform Building
https://graphics.tu-bs.de/teaching/ss19/padi/
Outline
https://graphics.tu-bs.de/teaching/ss19/padi/
Static libraries (.a/.lib)
additional files.
compilation.
your binary.
in multiple applications.
multiple apps.
compilation.
know location of files during runtime.
https://graphics.tu-bs.de/teaching/ss19/padi/
Building Libraries
https://graphics.tu-bs.de/teaching/ss19/padi/
Building Libraries
CXX=g++ OBJEXPORTPATH=../libobjexport OBJEXPORTLIB=objexport CXXFLAGS=-Wall -I$(OBJEXPORTPATH)/include -g -c LDFLAGS=-L$(OBJEXPORTPATH)/lib -l$(OBJEXPORTLIB) -g EXE=my_application $(EXE): main.o $(CC) -o $@ $^ $(LDFLAGS) main.o: main.cpp $(CC) $(CCFLAGS) $< […]
https://graphics.tu-bs.de/teaching/ss19/padi/
CMake and libraries
to include the [lib] library.
https://graphics.tu-bs.de/teaching/ss19/padi/
External library: OpenCV
https://graphics.tu-bs.de/teaching/ss19/padi/
External library: OpenCV
INCPATH = -I/usr/include/opencv LIBPATH = -L/usr/lib/ OPTIONS = -lcv -lcvaux -lcxcore -lhighgui -lstdc++ CCFLAGS = -Wall -g EXE=assignment_04 $(EXE): main.o g++ $(LIBPATH) $(OPTIONS) $^ -o $@ main.o: main.cpp g++ $(INCPATH) $(CCFLAGS) -c $< clean: rm -f *.o *~ $(EXE) testsmooth.png
https://graphics.tu-bs.de/teaching/ss19/padi/
Outline
https://graphics.tu-bs.de/teaching/ss19/padi/
Assertions
… but in a useful way! #include <cassert> void foo(float probability) { assert(0.0f <= probability && probability <= 1.0f); // do something ... }
#define NDEBUG // or use the –DNDEBUG flag with g++
https://graphics.tu-bs.de/teaching/ss19/padi/
Debugging with gdb
https://graphics.tu-bs.de/teaching/ss19/padi/
Debugging with gdb
gdb ./our_application (gdb) run
std::allocator<Quad> > Conifer::getQuads() const: Assertion 'center.z > 0.0' failed. (gdb) bt #0 raise () from /lib/libc.so.6 #1 in abort () from /lib/libc.so.6 #2 in __assert_fail () from /lib/libc.so.6 #3 in Conifer::getQuads at Conifer.cpp:31 #4 in Estate::getQuads at Estate.cpp:32 #5 in main () at main.cpp:42 (gdb) up #1 in abort () from /lib/libc.so.6 (gdb) up #2 in __assert_fail () from /lib/libc.so.6 (gdb) up #3 in Conifer::getQuads at Conifer.cpp:31 (gdb) display m_size->z 1: this->m_size->z = 0
https://graphics.tu-bs.de/teaching/ss19/padi/
Outline
https://graphics.tu-bs.de/teaching/ss19/padi/
Programming with IDEs
https://graphics.tu-bs.de/teaching/ss19/padi/
Back to building: QMake
qttest.pro
CONFIG -= qt # We won't be using Qt TEMPLATE = app # We're building an application... TARGET = QtTest # ... and it's called “QtTest” # Everything that ends in .h is a header file HEADERS += *.h # Everything that ends in .cpp is a source file SOURCES += *.cpp # Do not use this notation in a bigger project...
https://graphics.tu-bs.de/teaching/ss19/padi/
Programming with IDEs
https://graphics.tu-bs.de/teaching/ss19/padi/
Outline
https://graphics.tu-bs.de/teaching/ss19/padi/
Assignment
Download the new materials. It’s a solution of last week’s assignment.
You may have noticed that the “solution” contains several bugs.
https://graphics.tu-bs.de/teaching/ss19/padi/
Assignment
Which files go into the library? Which do not?
You may just recycle the old main.cpp.
Remember, you have to distribute both your library’s object files as well as all the necessary header files. You will also want a CMake script that builds the library.
Download and build a library (SFML), and write a small application. http://www.sfml-dev.org/ http://www.sfml-dev.org/documentation/2.3.2/
https://graphics.tu-bs.de/teaching/ss19/padi/
Using SFML
https://graphics.tu-bs.de/teaching/ss19/padi/
Final remarks
https://graphics.tu-bs.de/teaching/ss19/padi/