compiler-flags

Appending to CMAKE_C_FLAGS

白昼怎懂夜的黑 提交于 2019-12-06 19:39:09
问题 I'm using CMake for a project that comes in two versions, one of which requires -lglapi and the other does not. So far the lines we used look like that: SET(CMAKE_C_FLAGS "-O3 -xSSE3 -restrict -lpthread -lX11 -ldrm") SET(CMAKE_CXX_FLAGS "-O3 -xSSE3 -restrict -lpthread -lX11 -ldrm") I added an if statement in my CMakeList.txt exactly after those lines: if(SINGLE_MODE) SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} " -lglapi") SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} " -lglapi") endif(SINGLE_MODE) The SINGLE

How to add std=c++11 flag to clang-cl?

不想你离开。 提交于 2019-12-06 06:30:32
问题 I tried to compile a C++11 program with clang-cl under Windows. Clang-cl is the wrapper around clang to be more compatible with cl (Visual Studio compiler). I tried to add -std=c++11 and /std=c++11 and both get rejected. This is to no surprise as cl has no C++11 flag. But I can not use C++11 features with clang-cl. How can I enable C++11 support in clang-cl? 回答1: In the documentation mentioned before says: http://clang.llvm.org/docs/UsersManual.html#clang-cl clang defaults to C++11 for

Should I use “-ansi” or explicit “-std=…” as compiler flags?

99封情书 提交于 2019-12-05 13:58:15
问题 I've read that ANSI C is not exactly the same as ISO C and compilers may differ in interpretation of what "-ansi" is about. (gcc maps it to C90, clang maps it to C89) At the moment I would tend to use "-std=..." over "-ansi" as then it is explicitly shown which standard is used. As I am specifically interested in compiling on Linux, Windows and MAC, I fear some compilers could not understand "-std=..." but "-ansi". So are there any pros and cons for using the one over the other? 回答1: If you

Why can't clang enable all sanitizers?

此生再无相见时 提交于 2019-12-05 13:18:46
问题 Clang has various sanitizers that can be turned on to catch problems at runtime. However, there are some sanitizers that I can't use together. Why is that? clang++-3.9 -std=c++1z -g -fsanitize=memory -fsanitize=address -o main main.cpp 1 clang: error: invalid argument '-fsanitize=address' not allowed with '-fsanitize=memory' It's not a big deal, but when I run my unit tests, it takes longer than it should, because I have create multiple binaries for the same tests, and run each of them

Influencing function cloning/duplication/constant propagation in gcc

牧云@^-^@ 提交于 2019-12-05 08:48:06
When running gcc with optimizations-on, it clones (duplicates) C functions when it considers that the function is in a hot path or there's constants propagating to the function arguments. More specifically, this seems to be controlled by the fipa-cp-clone option. Is there any way to influence this? For instance mark one parameter with some attribute, as a compile-time constant (like you can do in C++ with a template parameter) which will cause the function to be cloned? What matters is whether the function is called with a constant argument (either an actual constant expression , or something

What flag silences GCC's warning about no newline at file-endings?

岁酱吖の 提交于 2019-12-05 06:54:28
I just read this post about why new-line warnings exist, but to be honest my team has people working on several different platforms and with several different editors (everyone uses what bests suites them), so the warning has become ubiquitous, and since its not really a warning worth taking care of it's become noise and makes finding serious warnings a hassle. Many times important warnings have gone unnoticed because, people got used to having a gazillion useless warnings pass by, so they obviously just stop looking at them carefully, and with reason IMHO. One could say in our case GCC is

Disadvantages of using the `-Wextra` flag when compiling in GCC

我的未来我决定 提交于 2019-12-05 04:29:41
I know that one should always compile with both -Wall and -Wextra as they enable warnings and help us to understand our mistake, if any. I've read that the -Wextra compiler flag is not recommended to use because it is too verbose with a lot of false positives. I was quite surprised on reading this. So I started googling about it but I didn't get any answer as all the search results showed was "what does the -Wextra flag do?". So, my questions are In which all situations does the -Wextra flag emit uneccessary warnings? Is it possible to stop the -Wextra flag from enabling the other flags that

Appending to CMAKE_C_FLAGS

为君一笑 提交于 2019-12-05 01:03:46
I'm using CMake for a project that comes in two versions, one of which requires -lglapi and the other does not. So far the lines we used look like that: SET(CMAKE_C_FLAGS "-O3 -xSSE3 -restrict -lpthread -lX11 -ldrm") SET(CMAKE_CXX_FLAGS "-O3 -xSSE3 -restrict -lpthread -lX11 -ldrm") I added an if statement in my CMakeList.txt exactly after those lines: if(SINGLE_MODE) SET(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} " -lglapi") SET(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} " -lglapi") endif(SINGLE_MODE) The SINGLE_MODE variable is defined a little up. When I use the message command to display the content of the

How do I dump gcc warnings into a structured format?

喜欢而已 提交于 2019-12-04 18:04:00
Like many, I build my project with the an abundance of warning flags. Since not all warning flags are detrimental, the compilation becomes noisy. Warnings such as "unused variables", "shadowing members in initialization lists", "missing switch defaults", are all important to log, but they create too much clutter during builds, and it is hard to spot the important warnings. Given a large project, there can be thousands of warnings mixed in with build statements, and parsing though it afterwards becomes burdensome. It's equally undesirable to maintain compiler pragmas and push/pop warnings

How can I pass the output of a command as a compiler flag through a Qt project file?

好久不见. 提交于 2019-12-04 17:47:58
I'm trying to add the output of "git describe" to the about window of my application, so it's easier to find out what version of the application people use. I can do it by adding the following compiler flag: -DAPP_VERSION="$(git describe HEAD)" But since the project is based on qmake, I would like to find a way to put this into the Qt project file. Is this possible? And if so, how? edit: I tried adding the following: QMAKE_CXXFLAGS += -DAPP_VERSION="$(git describe HEAD)" But it just gave me "-DAPP_VERSION=", so I suppose I have to use some escape characters, but I don't know which ones and