Adding MAKEFLAGS from MPC(The Makefile, Project, and Workspace Creator) - c++

I am using MPC to generate my makefiles. I generate successfully the Makefile but when I run make I get the following error:
error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support is currently experimental, and must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
My question is, how to add build flags (eg:-std=c++11) to my MPC?
For completion here is my MPC file:
project(Makefile) : dcpsexe, dcps_tcp {
requires += no_opendds_safety_profile
exename = start
after += *idl
TypeSupport_Files {
Communication.idl
}
Source_Files {
ListenerReader.cpp
Publisher.cpp
Subscriber.cpp
main.cpp
}
}

This can be done through the $ACE_ROOT/include/makeinclude/platform_macros.GNU file. Add a line with c++11=1 to the top of this file, that will enable C++11 support for the compiler.

Alternatively to enabling C++11 (or later) specifically for the platform this can be achieved on project basis, too, e.g.
specific(make) {
compile_flags += -std=c++20
}
make has been selected according to MPC documentation, I haven't tested myself (but did for a MSVC project where it worked seamlessly) – possibly the undocumented gcc (or clang) compiler options might be supported as well (the equally undocumented vs2019 and vs2022 ones definitely are so), you'll have to try yourself...

Related

std::numbers has not been declared - GCC 11.2 on Windows

I have GCC 11.2.0 installed on my Windows 10 machine (from here: https://winlibs.com/). I have updated the environment variable Path to C:\MinGW\bin
gcc version 11.2.0 (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders)
I'm using VSCode with the C/C++ extension configured to use the correct compiler path.
I want to use a C++20 feature which is
std::numbers::sqrt2
Still I get an error telling me it doesn't know std::numbers
[Running] cd "c:\Users\XX\XX\" && g++
main.cpp -o main && "c:\Users\XX\XX\"main
main.cpp: In function 'double sin_x_plus_cos_sqrt2_times_x(double)':
main.cpp:15:41: error: 'std::numbers' has not been declared
15 | return std::sin(x) + std::cos( std::numbers::sqrt2 * x );
|
I've added the header #include <numbers>
What am I missing ?
Default version of c++ standard for this version of gcc is C++17.
See this: https://godbolt.org/z/4Pjzd5r7s
Use
g++ main.cpp -o main -std=c++20
to force C++20
There is some support of C++20 in gcc, but it is simply to early to make it default standard.
What am I missing ?
In order to use C++20 features, you need to select the C++20 standard version.
Both gcc 10 & 11 require -std=c++20 on the command line for std::numbers to work. (Older versions than that don't support std::numbers at all)
https://gcc.gnu.org/projects/cxx-status.html#cxx20 shows progress on standards compliance. I would expect a standard to become default soon after all the details of the standard are met. As of Nov 2021, it seems they've got pretty much everything except some remaining details of the C++20 "modules" features.

how to configure -std=c++11 as default compiler?

Hi i am working on C++11 related feature , i need to include header file such as
#include <zmqpp/zmqpp.hpp>
in my source code and i wrote some simple g++ script to compile it such as
g++ client.c -o client
i just realized i need to run it with additional argument
g++ -std=gnu++11 client.c .......
in order for me compile successfully.
I am curious what is the default compiler for g++? is it possible for me set
-std=gnu++11 as my default c++ compiler?
Let me know if this duplicated, i was googling around but i don't see any information related to my scenario. Thanks
as stated here, the only way to change the standard version is to rebuild a custom version of g++. If you are using Linux, I recommend having a custom alias in .bashrc, like so:
alias g++11='g++ -std=c++11';
CMake is another common method to do this, simply add this directive to make the default version C++11 :
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
Keep in mind CMake is typically used for projects, so it may not be applicable to your use case.

How to specify c++ 14/17 with bazel.rc (tool specific to using GCC /G++, project not open to other tool chains)

Within my bazel.rc file for the C++ Bazel build options, I have specified:
'build --cxxopt="-std=c++1y"'
When I try to change to build --cxxopt="-std=c++14", bazel Throws error of :
''build --cxxopt="-std=c++14"' is not an option'
, with a cursor below 4 in c++14. If I change the 4 to y (c++1y), it compiles with no problem. I tried adding 'std:make_unique' in my code (c++14 addition) , and it clearly does not compile (make _unique is not part of std) which is assume is complaining that c++14 is not set as the standard, hence no make_unique for me.
What is the latest supported version of C++ in bazel? More specifically, how do I enable C++14 / C++17 (and even C++2x) for Bazel build, it those are supported? Thanks!
NOTE: this is not the same as How to set C++ standard version when build with Bazel??. (I am not asking about cpp 11 and I am asking about a very specific toolchain -- GCC/g++) I am not using any of the tools suggested by that thread. I am using GCC / g++ and am restricted in not being able to use the tools suggested by the answer in the previous question, I've RTFMd and googled. Thanks in advance.

C++14 support in QtCreator with Clang

How can I enable C++14 support in QtCreator 3.3 using Clang 3.5? I have added a Clang kit and I have added CONFIG += c++14 in my project file. However when using e.g. return type deduction I get the following error:
error: 'auto' return without trailing return type; deduced return types are a C++1y extension
you can use CONFIG += c++14 in .pro file with Qt5.5
but there is a bug with clang, so we need to modify the Qt/5.5/clang_64/mkspecs/features/c++14.prf file,
add this code beforeinclude(c++11.prf) :
contains(QMAKE_LFLAGS_CXX11, -stdlib=libc++) {
QMAKE_CXXFLAGS_CXX11 += -stdlib=libc++
}
I had to go to the Makefile in the build folder and manually replace -std=c++11 with -std=c++14.
Thankfully the Makefile is only written once when you add the kit to the project. I only had to do this once and could build in QtCreator as often as I want.
So now I can use a Clang kit to use all the new c++14 features. As a bonus, I can also use all the c++17 features if I manually set -std=c++1z in the Makefile. Sweet!

How can I use C++14 features when building qmake projects?

I'm currently using C++11 features in my Qt applications. However, I'd like to use some of the new C++14 features in my applications.
To enable C++11 in a Qt application, one only needs to add one line in the qmake project file, namely:
CONFIG += c++11
or this for earlier versions:
QMAKE_CXXFLAGS += -std=c++1y
I already tried to do the same with C++14, but it didn't work. I changed the above mentioned line of the qmake project like this:
CONFIG += c++14
or this for earlier versions:
QMAKE_CXXFLAGS += -std=c++1y
After that, lots of compilation errors, that did not exist before, appear when trying to build the project. The project compiles fine, however, if I try to use any C++14 features, I get a compilation error. This is an example:
template<typename T>
constexpr T pi = T(3.1415926535897932385);
This is the corresponding error:
main.cpp:7: error: template declaration of 'constexpr const T pi'
constexpr T pi = T(3.1415926535897932385);
^
How to enable C++14 features when using a qmake project in QtCreator?
I am using Qt 5.3.2, Qt Creator 3.2.1, and MinGW 4.8.2 32 bit.
This is now supported properly from Qt 5.4. You just type this into your qmake project file:
CONFIG += c++14
The necessary code change went in the middle of 2014 by Thiago:
Add support for CONFIG += c++14
I have just created the necessary documentation change:
Mention the c++14 CONFIG option in the qmake variable reference
Please note that variable templates are only supported from gcc 5.0, but then your code works just fine. This can be used for testing C++14 with older gcc:
main.cpp
#include <iostream>
int main()
{
// Binary literals: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3472.pdf
// Single-quotation-mark as a digit separator: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3781.pdf
std::cout << 0b0001'0000'0001;
return 0;
}
main.pro
TEMPLATE = app
TARGET = main
CONFIG -= qt
CONFIG += c++14
SOURCES += main.cpp
Build and Run
qmake && make && ./main
Output
257
Qt Creator is just an IDE.
You can think of IDEs as "smarter text editors" that aid the developer with debugging, building, code completion, file management and so on.
IDEs are irrelevant during compilation.
What matters is your compiler. And it is independent from your IDE.
g++ 4.8.x does not support many C++14 features: check out this page to learn what C++14 features are supported.
For some weird reason this is what Qt does:
If the compiler is gcc or mingw, CONFIG+=C++14 is transformed to a compiler flag -std=c++14 (that what you expect)
If it's another compiler (like clang), CONFIG=C++14 is stupidly transformed to -std=c++11 (sic!), so you will get errors about unsupported features, even if your clang version correctly supports C++14.
To fix it, specify the flag explicitly:
QMAKE_CXXFLAGS += -std=c++14
This way, you're sure that your compiler (g++, mingw or clang) will receive the correct flags.
To use C++14 with qmake with versions before Qt 5.4 (it doesn't make any difference wether you use it with Qt Creator or with some other IDE or from command line) and gcc, add this to your .pro file:
QMAKE_CXXFLAGS += -std=c++1y
qmake got support for CONFIG += c++14 with Qt 5.4, so you can use that for projects where you are comfortable with requiring at least that version of Qt. Be sure to either use the explicit compiler flags, or use the CONFIG option, but not both at the same time, to avoid conflicting switches.
Unfortunately gcc 4.8.2 supports very few C++14 features (see here), but you can test that with this code snippet:
#include <iostream>
auto f() { return 42; }
int main()
{
std::cout << f() << std::endl;
}
That will compile fine with QMAKE_CXXFLAGS += -std=c++1y, but give warning with CONFIG += c++11 or QMAKE_CXXFLAGS += -std=c++1x.