1

I use the Clear Linux distro (made by Intel) to build some C++ project that uses CMake. I run cmake and than make commands. When the make builds the code there is some warning about maybe-uninitialized and that warning is treated as an error, because the C++ compiler has been ran with a -Werror option. Currently I can't figure out where that -Werror option was added from. Please help me to find.

I've found that the default value of the CXXFLAGS environment variable in Clear Linux is stored at /usr/share/defaults/etc/profile as following:

CFLAGS="-g -O3 -feliminate-unused-debug-types -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-
size=32 -Wformat -Wformat-security -m64 -fasynchronous-unwind-tables -Wp,-D_REENTRANT -ftree-loop-distribute-patterns -Wl,-z -Wl,now
 -Wl,-z -Wl,relro -fno-semantic-interposition -ffat-lto-objects -fno-trapping-math -Wl,-sort-common -Wl,--enable-new-dtags -mtune=sk
ylake -Wa,-mbranches-within-32B-boundaries"
FFLAGS="-g -O3 -feliminate-unused-debug-types -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-
size=32 -m64 -fasynchronous-unwind-tables -Wp,-D_REENTRANT -ftree-loop-distribute-patterns -Wl,-z -Wl,now -Wl,-z -Wl,relro -malign-d
ata=abi -fno-semantic-interposition -ftree-vectorize -ftree-loop-vectorize -Wl,--enable-new-dtags -Wa,-mbranches-within-32B-boundari
es "
FCFLAGS="-g -O3 -feliminate-unused-debug-types -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer
-size=32 -m64 -fasynchronous-unwind-tables -Wp,-D_REENTRANT -ftree-loop-distribute-patterns -Wl,-z -Wl,now -Wl,-z -Wl,relro -malign-
data=abi -fno-semantic-interposition -ftree-vectorize -ftree-loop-vectorize -Wl,-sort-common -Wl,--enable-new-dtags "
CXXFLAGS="$CFLAGS -fvisibility-inlines-hidden -Wl,--enable-new-dtags "

As you can see it doesn't contain the -Werror option yet.

Another location, where the CXXFLAGS could be overriden is /etc/profile but it doesn't exist. Local user's ~/.profile and ~/.bashrc also don't override the CXXFLAGS.

So where CMake appends additional CXXFLAGS from? Does it have some built-in additions for the CXXFLAGS?

I'm pretty sure they don't come from the project itself because otherwise that project developers were also not able to build their code. Also I experienced the same issue when tried to build glibc according to instructions of Linux From Scratch. Could it be something specified to the Clear Linux distro that I use? But I'm doubt Intel has fixed all warnings in all C/C++ code their distro use.

Rostislav Krasny
  • 577
  • 3
  • 14
  • So, it is a *typo*-sort of questions: you have found that information stated in the question - "`CMakeLists.txt` files of the C++ project that I try to build also don't have any -`Werror`." - is **not correct** and that immediately resolves the problem. Lets close/delete the question. – Tsyvarev Sep 26 '20 at 16:58
  • I've edited my question by removing my first wrong conclusion about the `CMakeLists.txt` files. – Rostislav Krasny Sep 26 '20 at 17:21
  • But with that edit the question becomes.. **useless**: you ask about the project's behavior but reveal nothing about the project's code. You have obtained an experience after asking the question, but your question has no value for others. Why don't you want to simply delete it? There is nothing wrong in deleting wrongly asked questions. – Tsyvarev Sep 26 '20 at 17:46
  • This question still useful for all those who try to find the standard way of appending to the default value of `CXXFLAGS`. I was not able to find an answer to that question here and also in Google before I asked it here and then found the answer by myself. If you still think it should be deleted ask moderators. – Rostislav Krasny Sep 26 '20 at 18:07
  • Thank you for posting this question. I am new to Clear Linux and had no idea where `_FORTIFY_SOURCE=2` was coming from. I can now take this setting out of `/usr/share/defaults/etc/profile` and place it in `CMakeLists.txt` _conditionally_, for release builds only. – MikeOnline Dec 24 '21 at 07:30

1 Answers1

1

Sometimes asking a question is a good way to find an answer by yourself.

Actually the CMakeLists.txt in the root project's directory adds it:

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-unknown-warning-option -Wall -Wextra -Werror -Wmissing-declarations -std=c++2a -fdiagnostics-color=always")

I've just missed it out.

Rostislav Krasny
  • 577
  • 3
  • 14