Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make: No rule to make a header file?

I am trying to make a project using a library named BigInt. My file structure is:

/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

The Fibonacci3 Makefile is as of

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)

and the bigint Makefile is as of (shortened)

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

however, make reports that it could not find a rule for a header file?

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

What is happening here? Headers are supposed to be included, not compiled, so why is make asking for one?

Thanks in advance!

Solution:

Instead of including the makefile, compile the sources in my own makefile. It worked! Thanks again.

like image 617
ihsoy ih Avatar asked Dec 18 '12 14:12

ihsoy ih


People also ask

What should never be in a header file?

using declaration (the most common being using namespace std; ) should not appear in a header file because they pollute the namespace of the source file in which it is included.

How can you make a header file not to include multiple times?

To avoid multiple inclusions of the same header file we use the #ifndef, #define and #endif preprocessor directives. Just write the entire program in only file and include headers once only.

Can you write C++ without header files?

You can write all the code in header files (it is actually a very used practice in generic programming in C++), but this implies that every C/CPP file including that header will imply recompilation of the implementation from those header files.


1 Answers

The make program expects all files to be in the current directory. Since you include the second makefile into the current makefile, all files in that are relative to the current directory as well. You have to make sure that the files in the included makefile contains the correct paths.

like image 198
Some programmer dude Avatar answered Oct 15 '22 04:10

Some programmer dude