Makefile to support c++11

13,441

change this:

main.o: main.cpp
    g++ -c main.cpp

to:

main.o: main.cpp
    g++ -std=c++11 -c main.cpp

You may as well use something like this as basis for your Makefile:

CXX=g++
CXXFLAGS=-g -Wall -MMD -std=c++11
LDLIBS=-lm # list libs here
output: main.o google_api.o
clean:
    $(RM) *.o *.d output
-include $(wildcard *.d)

There are also similar questions on stackoverflow: Makefile c++11 support

Share:
13,441
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

    I recently started a small project in C++. I created a simply Makefile:

    output: main.o google_api.o
        g++ main.o google_api.o -o output
        rm *.o
        clear
        ./output
    
    main.o: main.cpp
        g++ -c main.cpp
    
    test.o: google_api.cpp google_api.h
        g++ -c google_api.cpp
    

    And when I compile my code I get the next error -

    non-aggregate type 'vector' cannot be initialized with an initializer list

    I am check for this issue and find that I need to add -std=c++11 support to my makefile to fix the problem. I add this command to the code:

    g++ -std=c++11 main.o google_api.o -o output

    But this is not make any change. I would love if someone can help me to fix this problem. Thanks