Passing CXXFLAGS to make has no effect - c++

I am trying to compile some software with make on Ubuntu 16.04. However, it fails with the error:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file
requires compiler and library support for the ISO C++ 2011 standard. This
support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
A quick websearch shows that compiler options can be passed to make either by
export CXXFLAGS="-std=c++11"
or
make CXXFLAGS="-std=c++11"
None of those options have worked. I have also tried with deleting everything in the build folder and starting from scratch. The error still persists.
How can I pass CXXFLAGS to make ?

Related

What's CMAKE_CXX_FLAGS and which are available

I've been doing C++ for a long long time, but I come from the land of Windows.
I've been handed a project that uses CMake. I've googled around trying to learn it.
I run cmake .
I assume it always looks for CMakeLists.txt and generates makefiles.
This creates a bunch more cmake files and make files.
I was then instructed to run make package.
I assume package is just a target name that could be anything.
I then get errors:
c++: error: unrecognized command line option ‘-mthumb-interwork’
c++: error: unrecognized command line option ‘-mfloat-abi=hard’
c++: error: unrecognized command line option ‘-mfpu=neon’
I think those are due to the fact that I am trying to compile for a different architecture then the one I am on. I assume all the cmake files would set that up correctly for me. I also assume that nothing there is proprietary.
I see the line in the CMakeLists.txt
SET(CMAKE_CXX_FLAGS "-march=armv7-a -mthumb-interwork -mfloat-abi=hard -mfpu=neon -mtune=cortex-a9 -std=c++11 -O3")
If I look at the official cmake documentation, it says, and I quote
"Flags for all build types." ....Not very helpful
I am thinking it isn't using the correct compiler, but I also don't see where in the CMakeLists.txt the compiler is specified at all.
The question is:
Why would these flags be unrecognized?
In the Linux world, it's often assumed that you don't need to specify the compiler by name; instead you arrange for c++ to refer to the compiler. That may involve setting PATH, creating a shell alias or a symbolic link.
Apparently you already did so, as your compiler is being called and is complaining about standard GCC flags - clearly your compiler isn't GCC.
The CMakeLists.txt file however is very much assuming it's intended for GCC. Don't blame CMake for that. CMake is the tool, CMakeLists.txt are project-specific instructions. This is a problem of whoever created the particular CMakeLists.txt file.
There's no easy fix. There is a real possibility that the -mfpu=neon option to gcc was necessary for the program, and it's anyone's guess what you'll need on the other compiler.

Add compiler support for c++ 2011

I try to compile a robot for torcs with the usage of opendavinci. The problem is that everytime i try to compile it
#error This file requires compiler and library support for the ISO C++ 2011 standard
appears. The obvious solution is to add the support, but i have a complicated makefile that is from torcs so i dont know how to work around this problem.
Is there any way to add the support without changing the makefile? I read about the CXXFLAGS that coud help me but i dont understand how it works.
The compiler is g++ 5.4.0 for Ubuntu
felix#ubuntufelix:/usr/src/torcs/torcs-1.3.7/src/drivers/bt$ make
g++ -I/usr/src/torcs/torcs-1.3.7/export/include -I/usr/src/torcs/torcs-1.3.7 -g -O2 -Wall -fPIC -fno-strict-aliasing -O2 -DUSE_RANDR_EXT -DGL_GLEXT_PROTOTYPES -Wall -fPIC -fno-strict-aliasing -O2 -DUSE_RANDR_EXT -DGL_GLEXT_PROTOTYPES -D_SVID_SOURCE -D_BSD_SOURCE -DSHM -DHAVE_CONFIG_H -c driver.cpp
In file included from /usr/include/c++/5/array:35:0,
from driver.h:15,
from driver.cpp:1:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
#error This file requires compiler and library support \
There's no completely standard way to build distributed software, but there should be a README or INSTALL file in the distribution, which gives more-or-less precise instructions. Ideally, distributions come with a configure script, and the installation process consists of ./configure; make; make install, possibly with some per-distribution special options given to ./configure. The basic process here is that the ./configure script edits suitable values into Makefile.in to generate Makefile, but such scripts can be arbitrarily complicated. Of course, things are rarely quite that simple, and building complicated software from source can be quite a technical challenge (this is why package managers are a Good Thing).
If there are no such installation instructions (have you double-checked?), then you should go back to the software distribution point and ask for help there (you're allowed to have a hint of reproach in your question as you do so – everyone, distributing even pre-beta software, should tell users how to build things).
If you've been left high and dry, however, then the following should broadly indicate where to look next:
You need to add an option to the invocation of the compiler, to tell it to support C++ 2011 features (I'm pretty sure g++ 5.4 has these features available, but they aren't enabled by default).
You do that by adding the -std=c++11 option to the compiler flags, and the way you do that is using the CXXFLAGS makefile variable that you measured (note: CXXFLAGS is the probable/conventional name for this variable, but it's not an inviolable rule).
Depending on how the Makefile is structured, you can add or adjust that variable in a number of ways.
Edit the Makefile – search for CXXFLAGS in the Makefile and add that -std option to that definition.
You will be able to redefine the variable on the make command line: make CXXFLAGS=-std=c++11, but that will stomp on any definition within the Makefile, which might be important.
The Makefile might be structured so that the definition includes CXXFLAGS=-foo -bar $(EXTRA_CXXFLAGS), which is there precisely so that you can call make with make EXTRA_CXXFLAGS=-std=c++11.
If there's a ./configure step to building this software, then there may be an option available to ./configure when doing that step (that doesn't sound like the case here).
But one way or another, your goal is to get -std=c++11 appearing in the compiler invocation that's produced by the Makefile. Note that if you give the -n option to make, then it will show you what commands it would produce, without actually doing anything.
Have fun.

GNU C++: unique_ptr.h no such file or directory

I am cross compiling some code from Windows on Linux machine (Kubuntu 16.05),g++ 5.4.0 64bit. Using Code Lite IDE as a dev env.
I have got several lines of code where I init unique pointer with
std::make_unique
The compiler complains with the error:
error: 'make_unique' is not a member of 'std'
I tried to add <memory> as well as <unique_ptr.h> to the header. Then the compiler complains that it can't find <unique_ptr.h> file. Interestingly,when I click to open the file from within the editor it is found and opened. The file is located in /usr/include/c++/5/bits/unique_ptr.h
I made sure that the compiler version that builds the code is indeed 5.4, so I don't understand why it doesn't support unique_ptr out of the box.I make sure to enable C++11 and C++14 flags:
-g;-O0;-std=c++14;-std=c++11;-Wall
Also, in the includes I add /user/include
What am I missing here? Do I have to include in the project the /usr/include/c++/5/bits/ directory explicitly?
Try these flags:
-g -O0 -std=c++14 -Wall. Note that semicolon is not needed for separating flags.
Compiler will take the latest entry of -std so you are effectively compiling with C++11 but not C++14.
As you can see HERE enabling -std=c++11 after a newer standard disables the first declared standard. Enabling only C++14 is enough.
C++11 introduced std::unique_ptr, but there was no std::make_unique (this broke the "symmetry" of shared_ptr/make_shared).
They fixed that in C++14, adding std::make_unique.
So, if you compile your code in C++11 mode, you can't use std::make_unique.
As others already pointed out, you need to set the latest C++ standard with the -std compiler option; in this case, it's -std=c++14 to enable also std::make_unique.

Enabling the -std=c++0x or -std=gnu++0x compiler options

I try to compile a particular source code written in C++, and I do not get an executable file. Instead, I get the following message from the terminal:
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/array:35,
from cpptesting.cpp:6:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/c++0x_warning.h:31:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
What does this message mean, and how can I fix the system? I have tried entering the directory 'include', but could find no 'c++' option. Does anyone have advice?
How do you compile it? if you are using console command like gcc .\cpptesting.cpp, you should just add an option to it:
gcc -std=gnu++0x .\cpptesting.cpp
If you are compiling more complex program with make, check a makefile.
By the way, you are using pretty old gcc version, in the more recent versions this standard is enabled by default(IIRC).

Warning while compiling libraries with both C and C++ files

I am working on the project which contains both C++ files and C files. In Code::Blocks, I have selected the following checkbox -std=c++11 in project build options.
Then get the following warning.
||warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default]|
If I also check the checkbox of -std=c99,
I will get an additional warning as the following.
||warning: command line option ‘-std=c99’ is valid for C/ObjC but not for C++ [enabled by default]|
Is there a way to work around this? Can I set the -std=c++11 flag for only the C++ files and -std=c99 for the C files?
I believe you are having this problem because you have enabled the -std=c++11
option in the Global compiler settings for GCC. I know you say you have enabled it
in "project build options", but enabling it in global compiler options is what causes
this behaviour.
It a bug in C::B that this global option is described as:
Have g++ follow the C++11 ISO C++ language standard
when in fact it will be applied to both g++ and gcc.
However you are probably ill-advised to set a C++ language standard option
in the global compiler options, even if it would only apply to g++. That
way, you won't ever be able to build any C++ projects that conform to
an earlier standard than C++11 but not C++11.
You should go back to Global compiler settings, click Reset defaults and
OK out. Then set the -std=c++11 compiler option (and any other non-default
options that you want) at the project level:
Right-click on your project in the workspace tree-view and open Build options.
Ensure the Selected compiler is GNU GCC Compiler and select the
Compiler settings -> Compiler flags tab. There you will see the
same list of checkboxes for compiler options that you saw in Global compiler settings.
Enable the -std=c++11 option and OK out.
Now, any .c files in your project will automatically be compiled with gcc,
without any g++-specific flags, and .cpp files will automatically be
compiled with g++, with -std=c++11 and any other g++ options you have
chosen.
Try reading this:
Using Global Compiler Variables
It describes different compiler variables, and build options. It is most likely there that you will need to either make a change or find out what variables are used specifically for each C and C++ targets that are compiled.