制作:没有规则制作头文件?

ihs*_* ih 5 c++ makefile header

我正在尝试使用名为 BigInt 的库创建一个项目。我的文件结构是:

/Users/wen/Projects/challenge/fibonacci3/fibonacci3.cpp
/Users/wen/Projects/challenge/fibonacci3/Makefile
/Users/wen/Projects/include/bigint/<.cc files and .hh files>
/Users/wen/Projects/include/bigint/Makefile
Run Code Online (Sandbox Code Playgroud)

Fibonacci3 Makefile 是从

LD_FLAGS = 
CC_FLAGS = 

# Include libraries

include /Users/wen/Projects/include/bigint/Makefile

# Build object files

%.o: %.cc %.cpp $(library-cpp)
    g++ -c -o $@ $(CC_FLAGS)

# Link object files

fibonacci3: fibonacci3.o $(library-objects)
    g++ -o $@ $(LD_FLAGS)
Run Code Online (Sandbox Code Playgroud)

和 bigint Makefile 是(缩短)

# Mention default target.
all:

# Implicit rule to compile C++ files.  Modify to your taste.
%.o: %.cc
    g++ -c -O2 -Wall -Wextra -pedantic $<

# Components of the library.

library-cpp = \
    BigUnsigned.cc \
    BigInteger.cc \
    BigIntegerAlgorithms.cc \
    BigUnsignedInABase.cc \
    BigIntegerUtils.cc \

library-objects = \
    BigUnsigned.o \
    BigInteger.o \
    BigIntegerAlgorithms.o \
    BigUnsignedInABase.o \
    BigIntegerUtils.o \

library-headers = \
    NumberlikeArray.hh \
    BigUnsigned.hh \
    BigInteger.hh \
    BigIntegerAlgorithms.hh \
    BigUnsignedInABase.hh \
    BigIntegerLibrary.hh \
Run Code Online (Sandbox Code Playgroud)

但是,make报告说它找不到文件的规则?

make: *** No rule to make target `NumberlikeArray.hh', needed by `BigUnsigned.o'.  Stop.
[Finished in 0.0s with exit code 2]
Run Code Online (Sandbox Code Playgroud)

这里发生了什么?标题应该被包含,而不是编译,那么为什么要要求一个呢?

提前致谢!

解决方案:

不包括 makefile,而是在我自己的 makefile 中编译源代码。有效!再次感谢。

Som*_*ude 4

make程序期望所有文件都位于当前目录中。由于您将第二个 makefile 包含到当前 makefile 中,因此其中的所有文件也都相对于当前目录。您必须确保包含的 makefile 中的文件包含正确的路径。