如何使用Make构建库并将其与源链接

时间:2012-12-19 17:44:59

标签: c++ makefile

我还是很新的。我正在尝试编译一个项目,其中maketest.cpp和maketest.hpp依赖于Users/wen/Projects/maketest和Makefile本身。问题是,我想在.cc中编译和链接源文件(.hhUsers/wen/Projects/include/bigint)。

# Macros

INCLUDE = -I/Users/wen/Projects/include/bigint
LIBS =

CC = g++
override FLAGS += -O2

HEADERS= $(wildcard *.hpp) $(wildcard Users/wen/Projects/include/bigint/*.hh) 

# EXE Name
INSTALL = maketest

CC_FILES = %.cpp Users/wen/Projects/include/bigint/%.cc
OBJ_FILES = maketest.o $(wildcard Users/wen/Projects/include/bigint/*.o)

# Rules

$(INSTALL): $(OBJ_FILES)
    $(CC) $(FLAGS) $^ -o $@ $(LIBS)

%.o: $(CC_FILES) $(HEADERS)
    $(CC) $(FLAGS) $(INCLUDE) -c $< -o $@

# Installation types

install: $(INSTALL)

release:
    @echo "Re-run with parameter:"
    @echo "FLAGS=-D_RELEASE"

debug:
    @echo "Re-run with parameter:"
    @echo "FLAGS=-D_DEBUG"

# Cleaning up

clean:
    rm -f $(OBJ_FILES) $(INSTALL)

代码编译maketest.cpp并链接它,但不是bigint。

Users/wen/Projects/include/bigint构建和链接文件的正确方法是什么?非常感谢!

1 个答案:

答案 0 :(得分:1)

我最后想出来了,谢谢周杰伦。问题是我忘记了Users/wen/Projects/include/bigint前面的斜线,所以它不是从root搜索而是搜索项目文件夹。现在它有效!

  

尝试在OBJ_FILES中明确指定bigint中的一个文件(也许是“bigint.o”?)。我不认为你的通配符正在得到你想要的东西。