I tried to create a Makefile using the main.cpp, factorial.cpp, hello.cpp and function.h files. Typing "make" in the Linux command prompt window, it shows:
g++ -c -o hello main.o factorial.o hello.o g++: main.o: linker input file unused because linking not done g++: factorial.o: linker input file unused because linking not done g++: hello.o: linker input file unused because linking not done
I am doing a makefile for the first time. Please give advice, what could be the problem? The Makefile contains the following code →
hello: main.o factorial.o hello.o g++ -c -o hello main.o factorial.o hello.o main.o: main.cpp g++ -c -o main.o main.cpp factorial.o: factorial.cpp g++ -c -o factorial.o factorial.cpp hello.o: hello.cpp g++ -c -o hello.o hello.cpp
The contents of a single file, if you want to see it: 1) main.cpp
#include<iostream> #include"functions.h" using namespace std; int main() { print_hello(); cout << endl; cout << "The factorial of 5 is " << factorial(5) << endl; return 0; }
2) hello.cpp
#include<iostream> #include "functions.h" using namespace std; void print_hello() { cout << "Hello World!"; }
3) factorial.cpp
#include "functions.h" int factorial(int n) { if(n!=1) { return(n * factorial(n-1)); } else return 1; }
4) function.h
void print_hello(); int factorial(int n);
source share