How do I use the implicit Makefile rule with .cpp files?

There is an implicit rule in C ++ Makefiles using the .C or .cc extension. But I usually have a .cpp extension for a C ++ source.

How do I use an implicit Makefile rule with .cpp files?

+3


source to share


2 answers


See Directory of Implicit Rules :



Compiling C ++ Programs

no is generated automatically from n.cc, n.cpp or nC with a recipe of the form $ (CXX) $ (CPPFLAGS) $ (CXXFLAGS) -c. We recommend using the ".cc" suffix for C ++ source files instead of ".C".

+4


source


This is from GNU to make docs .

The '% in the premise of the template rule means the same output that was matched by "% in target". For a template rule to apply, its target template must match the filename in question and all of its prerequisites (after template substitution) must name files that exist or can be made. These files become target prerequisites. Thus, a rule like

 %.o : %.c ; recipe...

      

indicates how to make file no, with another nc file as its prerequisite, provided nc exists or can be done.



So you can try something similar to

%.o : %.cpp %.hpp
   $(CC) $(CFLAGS) $@

      

0


source







All Articles