【问题标题】:Makefile C++11 - Compiling to static libraryMakefile C++11 - 编译成静态库
【发布时间】:2013-07-19 23:23:42
【问题描述】:

我正在尝试将我的源文件编译为静态库,但是它似乎不想工作。代码如下:

#-----------------------------------------------------------------------------
#   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

问题似乎在于我正在使用 C++11,因为实际代码无法编译。

有什么想法吗?

【问题讨论】:

    标签: c++ gcc compiler-construction makefile


    【解决方案1】:

    CCFLAGS 替换为CXXFLAGS,反之亦然。

    国旗拼写为-std=c++0x(感谢@Pixelchemist)。

    【讨论】:

    • SB 如果我使用:CCFLAGS 而不是 CXXFLAGS,我会得到以下信息:g++: error: unrecognized command line option '-std+c++0x'?
    • -std=c++11-std=c++0x= 不是 +
    • @Pixelchemist 谢谢.. 成功了!但现在我收到以下错误:g++ -o ../lib/libclient.a obj/file1.o obj/file2.o -static ld: library not found for -lcrt0.o
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-24
    相关资源
    最近更新 更多