c++gccmakefile

Makefile C++11 - Compiling to static library


I am trying to compile my source files to a static library, however, it doesn't seem to want to work. Here is the code:

#-----------------------------------------------------------------------------
#   Usage of make file
#-----------------------------------------------------------------------------
# Clean operation:
#   make -f MakeClient clean
#
# Make operation:
#   make -f MakeClient
#
#


#OBJ = $(SRC:.cpp=.o)
OBJ_DIR = ./obj

OUT_DIR= ../lib
OUT_FILE_NAME = libclient.a

# include directories
INCLUDES=-I. -I../common -I../../depends -I../../depends/zlib

# C++ compiler flags (-g -O2 -Wall)
CXXFLAGS := -Wall -Wextra -pedantic-errors -std+c++0x

  # compiler
  CCC = g++ 


  # Enumerating of every *.cpp as *.o and using that as dependency
  $(OUT_FILE_NAME): $(patsubst %.cpp,$(OBJ_DIR)/%.o,$(wildcard *.cpp))
    $(CCC)  -o $(OUT_DIR)/$@ $^ -static $(LIB_DIR) $(LIBS) -std=c++11

#Compiling every *.cpp to *.o
$(OBJ_DIR)/%.o: %.cpp dircreation
$(CCC) -c $(INCLUDES) $(CCFLAGS) -o $@ $<

dircreation:
@mkdir -p $(OUT_DIR)
@mkdir -p $(OBJ_DIR)

.PHONY : clean
clean:
rm -f $(OBJ_DIR)/*.o $(OUT_DIR)/$(OUT_FILE_NAME) Makefile.bak

The problem seems to be recognising that I'm using C++11 since the actual code does not compile.

Any ideas?


Solution

  • Replace CCFLAGS with CXXFLAGS, or vice versa.

    And the flag is spelled -std=c++0x (thanks, @Pixelchemist).