Reputation: 37
I received this sample makefile from my professor and I'm trying to run it on Ubuntu but the commands I'm typing won't run it. All the files in the makefile already exist and when I type make, it makes the files but the actual program doesn't run. I have tried to type ./a.out but that doesn't run it either. Please help me with what command to type for the program to run.
# Makefile for Library Management System
CXXFLAGS += --std=c++11
all: div main
rebuild: div clean main
debug: CXXFLAGS += -g
debug: rebuild
main: main.o controller.o view.o library.o publication.o
$(CXX) $(CXXFLAGS) -o lms main.o controller.o view.o library.o publication.o
main.o: main.cpp *.h
$(CXX) $(CXXFLAGS) -c main.cpp
controller.o: controller.cpp *.h
$(CXX) $(CXXFLAGS) -c controller.cpp
test_view: test_view.o controller.o view.o library.o publication.o
$(CXX) $(CXXFLAGS) -o test_view test_view.o controller.o view.o library.o publication.o
test_view.o: test_view.cpp view.h publication.h library.h
$(CXX) $(CXXFLAGS) -c test_view.cpp
test_library: test_library.o library.o publication.o
$(CXX) $(CXXFLAGS) -o test_library test_library.cpp library.o publication.o
test_library.o: test_library.cpp *.h
$(CXX) $(CXXFLAGS) -c test_library.cpp
library.o: library.cpp *.h
$(CXX) $(CXXFLAGS) -c library.cpp
test_publication: test_publication.o publication.o
$(CXX) $(CXXFLAGS) -o test_publication test_publication.o publication.o
test_publication.o: test_publication.cpp *.h
$(CXX) $(CXXFLAGS) -c test_publication.cpp
publication.o: publication.cpp *.h
$(CXX) $(CXXFLAGS) -c publication.cpp
clean:
-rm -f *.o lms test_age test_genre test_media test_publication test_library test_view test_view_actual.txt
div:
@echo
@echo 'X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-'
@echo '-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X'
@echo 'X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-'
@echo '-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X'
@echo
Upvotes: 0
Views: 1713
Reputation: 2896
The job of make
is to build the program, not run it, so the makefile is probably working just fine.
You can see from the line:
all: div main
that the makefile will try to build div
and main
by default.
There is a rule for div
that just prints things to the console:
div:
@echo
@echo 'X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-'
@echo '-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X'
@echo 'X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-'
@echo '-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X-X'
@echo
as noted in the comments of the other answer, the rule for main
has the flag to gcc -o lms
so the actual output executable name will be lms
.
You should really tell your professor that is is bad form, since a makefile is supposed to build a file with the same name as it's rule. (ie make main
should build a file called main
) Feel free to point him here if he disagrees.
Upvotes: 1
Reputation: 1390
Is there a file called 'lms'? Try running: ./lms
The things in the makefile after '-o' specify the output filenames. These are the programs you can run.
Upvotes: 3