Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

make is not using -std=c++11 option for g++

I am trying to compile c++ files using make. But, it is not using -std=c++11 flag by default. Whenever I need to compile a program which uses c++11 specific features, I have to explicitly compile it using g++.

So, I want to ask how can I have make automatically use the option -std=c++11 for all my c++ files on my system.

If I need to change some global makefile for g++ , what is the location of the makefile on Linux Mint 18 and what needs to be changed or added?

Or do I need to create a Makefile for myself?

EDIT 1: I am invoking make like

make myfile

And there are only .cpp files and their binaries in the directory. I don't have any Makefile in the directory.

EDIT 2: Here, myfile is the name of the c++ file which I want to compile.

When I run make with the -d option, I get the following output (I can not paste all of the output as it is quite long and is exceeding the body size limit so, I am including the screenshots of the output). Image 1
And this image(2) has some lines from the end.
Image 2

I intentionally made a change in the file "MagicalWord.cpp" so that make finds something to make!

like image 308
tonystark Avatar asked Jan 27 '26 04:01

tonystark


1 Answers

There is no "global makefile" and there is no way to change the default flags for all invocations of make (unless you edit the source code to GNU make and compile it yourself, which is a bad idea in this situation).

In your makefile(s), add the line:

CXXFLAGS += -std=c++11

Assuming you're using the built-in rules for compiling things, or that you're using the standard variables with your own rules, that will do what you need.

If that doesn't work we'll need to see your makefile or at least the rules you use to build your C++ source files (things like the -d output aren't useful here--that would be interesting if files weren't being built, that you thought should be or similar).

like image 190
MadScientist Avatar answered Jan 30 '26 08:01

MadScientist



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!