Skip to content

Instantly share code, notes, and snippets.

@isacdaavid
Created March 25, 2016 17:05
Show Gist options
  • Save isacdaavid/90474daef85074284a98 to your computer and use it in GitHub Desktop.
Save isacdaavid/90474daef85074284a98 to your computer and use it in GitHub Desktop.
# CCExtractor Sample Exercise No. 2 for GSoC 2016:
# Dealing with compiler warning messages
$ uname -srvm
Linux 4.4.2-gnu-1 #1 SMP PREEMPT Sat Feb 20 10:58:02 UYT 2016 x86_64
$ gcc --version
gcc (GCC) 5.3.0
### linux/build ###
$ gcc -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX -D_FILE_OFFSET_BITS=64 ... # these are the default
$ gcc -std=gnu99 -Wno-write-strings -DGPAC_CONFIG_LINUX ...
$ gcc -std=gnu99 -Wno-write-strings ...
$ gcc -std=gnu99 ...
$ gcc ...
### linux/Makefile ###
$ head Makefile
CC = gcc
SYS := $(shell gcc -dumpmachine)
CFLAGS = -O3 -std=gnu99
INCLUDE = -I../src/gpacmp4/ -I../src/libpng -I../src/zlib -I../src/lib_ccx -I../src/.
INCLUDE += -I../src/zvbi
ALL_FLAGS = -Wno-write-strings -D_FILE_OFFSET_BITS=64
LDFLAGS = -lm
ifneq (, $(findstring linux, $(SYS)))
CFLAGS +=-DGPAC_CONFIG_LINUX
endif
$ make
...
gcc -c -Wno-write-strings -D_FILE_OFFSET_BITS=64 -I../src/gpacmp4/ -I../src/libpng -I../src/zlib -I../src/lib_ccx -I../src/. -I../src/zvbi -O3 -std=gnu99 -DGPAC_CONFIG_LINUX ../src/zvbi/decoder.c -o objs/decoder.o
In file included from ../src/zvbi/decoder.c:30:0:
../src/zvbi/misc.h:384:0: warning: "strndup" redefined
# define strndup _vbi_strndup
^
In file included from /usr/include/string.h:630:0,
from ../src/zvbi/misc.h:32,
from ../src/zvbi/decoder.c:30:
/usr/include/bits/string2.h:1319:0: note: this is the location of the previous definition
# define strndup(s, n) __strndup (s, n)
^
gcc -c -Wno-write-strings -D_FILE_OFFSET_BITS=64 -I../src/gpacmp4/ -I../src/libpng -I../src/zlib -I../src/lib_ccx -I../src/. -I../src/zvbi -O3 -std=gnu99 -DGPAC_CONFIG_LINUX ../src/zvbi/sampling_par.c -o objs/sampling_par.o
In file included from ../src/zvbi/sampling_par.c:26:0:
../src/zvbi/misc.h:384:0: warning: "strndup" redefined
# define strndup _vbi_strndup
^
In file included from /usr/include/string.h:630:0,
from ../src/zvbi/misc.h:32,
from ../src/zvbi/sampling_par.c:26:
/usr/include/bits/string2.h:1319:0: note: this is the location of the previous definition
# define strndup(s, n) __strndup (s, n)
^
gcc -c -Wno-write-strings -D_FILE_OFFSET_BITS=64 -I../src/gpacmp4/ -I../src/libpng -I../src/zlib -I../src/lib_ccx -I../src/. -I../src/zvbi -O3 -std=gnu99 -DGPAC_CONFIG_LINUX ../src/zvbi/raw_decoder.c -o objs/raw_decoder.o
In file included from ../src/zvbi/raw_decoder.c:29:0:
../src/zvbi/misc.h:384:0: warning: "strndup" redefined
# define strndup _vbi_strndup
^
In file included from /usr/include/string.h:630:0,
from ../src/zvbi/raw_decoder.c:26:
/usr/include/bits/string2.h:1319:0: note: this is the location of the previous definition
# define strndup(s, n) __strndup (s, n)
^
gcc -c -Wno-write-strings -D_FILE_OFFSET_BITS=64 -I../src/gpacmp4/ -I../src/libpng -I../src/zlib -I../src/lib_ccx -I../src/. -I../src/zvbi -O3 -std=gnu99 -DGPAC_CONFIG_LINUX ../src/zvbi/bit_slicer.c -o objs/bit_slicer.o
In file included from ../src/zvbi/bit_slicer.c:24:0:
../src/zvbi/misc.h:384:0: warning: "strndup" redefined
# define strndup _vbi_strndup
^
In file included from /usr/include/string.h:630:0,
from ../src/zvbi/misc.h:32,
from ../src/zvbi/bit_slicer.c:24:
/usr/include/bits/string2.h:1319:0: note: this is the location of the previous definition
# define strndup(s, n) __strndup (s, n)
^
...
# All those 4 warnings are due to ccextractor source files using a custom
# strndup macro from src/zvbi/misc.h rather than the one coming from libc
# (/usr/include/bits/string2.h in my setup).
#
# Interestingly, after removing the -O3 optimization level warnings were gone.
# -O0 and -Os don't produce warnings.
# -O1, -O2, -O3 and -Ofast and -Og do produce the same warnings.
# According to the gcc manual -Os is most similar to -O2, but it disables 7
# optimizations and adds some of its own. However manually disabling those 7
# optimizations using their counterpart -fno flags while in -O2 or -O3 mode
# (the one specified in the Makefile) wasn't effective, which leads me to
# believe that something more complex is going on inside gcc.
#
# For reference, the culprit seems to be a function called warn_of_redefinition
# inside gcc's file libcpp/macro.c.
#
# There's no option to turn this macro redefinition warning off in gcc (there's
# one for built-in macros, but those don't apply here). So in my environment the
# only way to supress those warnings is by disabling all warnings with -w, or
# changing the optimization level or adding an #undef before the redefinition
# in src/zvbi/misc.h.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment