When I compile my library I have switched on -fPIC
because I want to be able to compile it as a shared and as a static library.
Using gcc 3.4.4 on cygwin I get this warning on all source files:
-fPIC ignored for target (all code is position independent)
And I really wonder what's the point of it. It tells me that I use a switch which has no effect because what the switch should achieve is already accomplished. Well, it means it's redundant, fine. But what's the point of it and how can I suppress it?
I'm not talking about why using PIC or not, just why it generates that IMO useless warning.
To disable a set of warnings for a given piece of code, you have to start with a “push” pre-processor instruction, then with a disabling instruction for each of the warning you want to suppress, and finish with a “pop” pre-processor instruction.
If the value of y is always 1, 2 or 3, then x is always initialized, but GCC doesn't know this. To suppress the warning, you need to provide a default case with assert(0) or similar code. This option also warns when a non-volatile automatic variable might be changed by a call to longjmp.
The TreatWarningsAsErrors option treats all warnings as errors. You can also use the TreatWarningsAsErrors to set only some warnings as errors.
Use -Wno-dev to suppress it. You can disable the warning like this when you are configuring your build.
and how can I suppress it?
Not only a useless warning, but a distraction that makes it difficult to follow other warnings and errors.
Given my make output consistently showed 3 related lines, I opted to filter out the 3 "useless" lines using the following:
make 2>&1 | sed '/PIC ignored/{N;N;d;}'
I realize this is not the ideal way to suppress the noise, but maybe it will help to some degree. Be advised that I'm cutting 3 lines where other situations may only require removal of just one line. Note that I'm also routing stderr to stdout.
Here's a snipit of make output without the sed filter:
libavcodec/x86/mlpdsp.c:51:36: warning: taking address of expression of type 'void'
&ff_mlp_iirorder_4 };
^
CC libavcodec/x86/motion_est_mmx.o
libavcodec/x86/motion_est_mmx.c:1:0: warning: -fPIC ignored for target (all code is position independent)
/* */
^
CC libavcodec/x86/mpegaudiodec_mmx.o
libavcodec/x86/mpegaudiodec_mmx.c:1:0: warning: -fPIC ignored for target (all code is position independent)
/* */
^
CC libavcodec/x86/mpegvideo_mmx.o
libavcodec/x86/mpegvideo_mmx.c:1:0: warning: -fPIC ignored for target (all code is position independent)
/* */
^
And the same with the sed filter:
^
libavcodec/x86/mlpdsp.c:51:36: warning: taking address of expression of type 'void'
&ff_mlp_iirorder_4 };
^
CC libavcodec/x86/motion_est_mmx.o
CC libavcodec/x86/mpegaudiodec_mmx.o
CC libavcodec/x86/mpegvideo_mmx.o
CC libavcodec/x86/proresdsp-init.o
Personally, I'd just add os detection to the makefile. Something along the lines of
TARGET_TRIPLE := $(subst -, ,$(shell $(CC) -dumpmachine))
TARGET_ARCH := $(word 1,$(TARGET_TRIPLE))
TARGET_OS := $(word 3,$(TARGET_TRIPLE))
ifeq ($(TARGET_OS),mingw32)
else ifeq ($(TARGET_OS),cygwin)
else
CFLAGS += -fPIC
endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With