2013-07-19 131 views
0

我想將我的源文件編譯爲靜態庫,但是,它似乎並不想工作。這裏是代碼:Makefile C++ 11 - 編譯爲靜態庫

#----------------------------------------------------------------------------- 
# 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)/[email protected] $^ -static $(LIB_DIR) $(LIBS) -std=c++11 

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

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

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

這個問題似乎認識到我正在使用C++ 11,因爲實際的代碼不能編譯。

任何想法?

回答

1

CCFLAGS替換爲CXXFLAGS,反之亦然。

而國旗拼寫-std=c++0x(謝謝@Pixelchemist)。

+0

SB如果我使用:'CCFLAGS'而不是'CXXFLAGS'我得到以下內容:'g ++:error:無法識別的命令行選項'-std + C++ 0x''? – Phorce

+1

'-std = C++ 11'或'-std = C++ 0x'。 ** = **不** + **。 – Pixelchemist

+0

@Pixelchemist謝謝..這工作!但現在我得到以下錯誤:'g ++ -o ../lib/libclient.a obj/file1.o obj/file2.o -static ld:找不到-lcrt0.o庫 – Phorce