Makefile .cpp.o: vs %o: %.cpp

mahesh

In make, what is the difference between:

%.o: %.cpp foolib.h
    $(CXX) -c $< -o $@ $(CXXFLAGS)

and

.cpp.o: foolib.h
    $(CXX) -c $< -o $@ $(CXXFLAGS)

?

Also, am I right in understanding that foolib.h should be included in the rules as shown above if the changes made in the header are to be (re)compiled even when there is no change in the .cpp files?

Maxim Egorushkin

.cpp.o: syntax is Old-Fashioned Suffix Rules.

Am I right in understanding that foolib.h should be included in the rules as shown above if the changes made in the header are to be (re)compiled even when there is no change in the .cpp files?

You are right. However, maintaining header dependencies this way is tedious and error-prone. People normally use auto-generated header dependencies.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

.cpp to .o files in Makefile

From Dev

.cpp to .o files in Makefile

From Dev

What does `OBJECTS = $(SOURCES:.cpp=.o)` mean in a makefile

From Dev

What does the target ".cpp.o:" mean in a Makefile?

From Dev

What does `OBJECTS = $(SOURCES:.cpp=.o)` mean in a makefile

From Dev

Modifying CUDA and cpp Makefile

From Dev

kernel.cpp showing error and Makefile error while making kernel.o

From Dev

cmake to create Makefile with *.cpp rule

From Dev

cmake to create Makefile with *.cpp rule

From Dev

makefile to compile all cpp files in all subdirs

From Dev

C++ makefile on Linux with Multiple *.cpp files

From Dev

Makefile to compile both c and cpp files

From Dev

Write makefile for .cpp and .hpp c++

From Dev

'Self' of python vs 'this' of cpp/c#

From Dev

Function method definition in .cpp vs .h

From Dev

debugging cpp in VS2010 error value

From Dev

'Self' of python vs 'this' of cpp/c#

From Dev

debugging cpp in VS2010 error value

From Dev

How to create a makefile for several .cpp files with .h files and main.cpp without a .h

From Dev

C++ Makefile error - No rule to make target '%.cpp'

From Dev

Error when running make for my Makefile.cpp

From Dev

C++ Makefile error - No rule to make target '%.cpp'

From Dev

Buildroot MakeFile for aws-iot-device-sdk-cpp

From Dev

Why does the compiler only generate object files .o only from .cpp files

From Dev

class template cpp, hpp, cpp

From Java

C++ code file extension? .cc vs .cpp

From Dev

C# UInt vs Cpp DWORD conflict with negative values

From Dev

How to setup in GDAL 1.9.2 CPP project on windows VS C++?

From Dev

.cpp vs .h and where should I put function definitions

Related Related

HotTag

Archive