I have a makefile problem. I know how to create a makefile for two, but not four different files including header files...
There are four files, main.cpp Dictionary.h Dictionary.cpp and Cinco.h
Cincotest: main.o Cinco.o
g++ -o p3 main.o Cinco.o
main.o: main.cpp Cinco.h
g++ -c main.cpp
Dictionary.o: Dictionary.cpp Dictionary.h
g++ -c .cpp
# clean up
clean:
rm -f p4 *.o *~
Do we need the other files code or could we get help here??
If you know the answer and could input the new code that would be perfect ;)
It looks to me like a fairly standard way of organizing code - .cpp
and a .h
header file to go with it.
The rules that you have are sufficient. Unless your main.cpp
also #include-s the Dictionary.h
header file, or your dictionary.cpp
also #include-s the Cinco.h
, in which case:
main.o: main.cpp Cinco.h Dictionary.h
g++ -c main.cpp
Dictionary.o: Dictionary.cpp Cinco.h Dictionary.h
g++ -c .cpp
A makefile
is just a dependency list. For each *.o
file, it's dependencies are all the source files needed to compile it. If in your main.cpp
you #include Dictionary.h
, then a change to Dictionary.h
means that main.cpp
needs to be recompiled, of course. Therefore, your dependency rule would indicate the same way.
Since you're using g++
, you can also use g++
to write your dependency rules for you. Try:
g++ -MM -MF main.deps main.cpp
See gcc
's man page for more information.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.