Multiple declaration of a function make command UNIX
<p>I have 2 files and i want to compile and run them using make command. I created a Makefile named "Makefile". They are compiled but shows an error </p>

<pre><code>all: hello
hello: pgm1.o pgm2.o
        g++ pgm1.o pgm2.o -o hello
pgm1.o: pgm1.cpp
        g++ -c pgm1.cpp
pgm2.o: pgm2.cpp
        g++ -c pgm2.cpp
</code></pre>

<p>They are compiled but shows an error </p>

<pre><code>make -f Makefile
g++ pgm1.o pgm2.o -o hello
pgm2.o: In function `print2()':
pgm2.cpp:(.text+0x0): multiple definition of `print2()'
pgm1.o:pgm1.cpp:(.text+0x0): first defined here
collect2: ld returned 1 exit status
make: *** [hello] Error 1
</code></pre>

<p>pgm1.cpp<br></p>

<pre><code>#include &lt;iostream&gt;
#include "pgm2.cpp"
using namespace std;
int main()
{
        cout&lt;&lt;"Thiss is program 1";
        print2();
        return 0;
}
</code></pre>

<p>&lt;>pgm2.cpp<br></p>

<pre><code>#include &lt;iostream&gt;
using namespace std;
void print2()
{
        cout&lt;&lt;"Thiss is program 2";

}
</code></pre>

<p>What is that error? How can i rectify it?</p>