Skip to content

Commit

Permalink
Documented the -Werror=format compilation flag
Browse files Browse the repository at this point in the history
Added compile-time format checking to C++17 NanoLog's example
GNUmakefiles and associated documentation. This helps users
avoid formatting errors that could corrupt the log file at
runtime (such as with issue #46) and closes issue #47.
  • Loading branch information
syang0 committed Nov 21, 2020
1 parent c8d82dd commit 39d2e53
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ The C++17 version of NanoLog works like a traditional library; just [``#include

To build the C++17 NanoLog Runtime library, go in the [runtime directory](./runtime/) and invoke ```make```. This will produce ```./libNanoLog.a``` to against link your application and a ```./decompressor``` application that can be used to re-inflate the binary logs.

When you compile your application, be sure to include the NanoLog header directory ([``-I ./runtime``](./runtime/)), and link against NanoLog, pthreads, and POSIX AIO (``-L ./runtime/ -lNanoLog -lrt -pthread``). Sample g++ invocations can be found in the [sample GNUmakefile](./sample/GNUmakefile).
When you compile your application, be sure to include the NanoLog header directory ([``-I ./runtime``](./runtime/)), link against NanoLog, pthreads, and POSIX AIO (``-L ./runtime/ -lNanoLog -lrt -pthread``), and enable format checking in the compiler (e.g. passing in ``-Werror=format`` as a compilation flag). The latter step is incredibly important as format errors may silently corrupt the log file at runtime. Sample g++ invocations can be found in the [sample GNUmakefile](./sample/GNUmakefile).

After you compile and run the application, the log file generated can then be passed to the ```./decompressor``` application to generate the full human-readable log file (instructions below).

Expand Down
2 changes: 1 addition & 1 deletion benchmarks/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ USER_SRCS=Benchmark.cc
ifeq ($(PREPROCESSOR_NANOLOG),yes)
CXXFLAGS= -std=c++11 -DNDEBUG -O3 -g
else
CXXFLAGS= -std=c++17 -DNDEBUG -O3 -g
CXXFLAGS= -Werror=format -std=c++17 -DNDEBUG -O3 -g
endif
CXX=g++

Expand Down
2 changes: 1 addition & 1 deletion integrationTest/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ endif
# Must be specified AFTER defining NANOLOG_DIR and USER_OBJ's
include $(NANOLOG_DIR)/NanoLogMakeFrag

CXXFLAGS= -std=c++17 -O3 $(CXXWARNS) -Werror
CXXFLAGS= -Wformat -std=c++17 -O3 $(CXXWARNS) -Werror

all: testApp basic_decompressor

Expand Down
6 changes: 4 additions & 2 deletions sample/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
#
#####################################################################

# -DNDEBUG and -O3 should always be passed for high performance
CXXFLAGS= -std=c++17 -DNDEBUG -O3 -g
# -Werror=format should _always_ be enabled to catch formatting errors
# early during compilation rather than at decompression.
# -DNDEBUG and -O3 are for high performance
CXXFLAGS= -Werror=format -std=c++17 -DNDEBUG -O3 -g

NANOLOG_RUNTIME_DIR=../runtime

Expand Down

0 comments on commit 39d2e53

Please sign in to comment.