I'm not really sure which operating system you use. you should be more precise. Anyhow, I will use the command line and the compiler g++ in windows.
Let's say you have main.cpp print.cpp print.h. OK
From the command line
First: you need to create the .obj for print.cpp as the following
>> g++ -c print.cpp -o print.obj
Then you need to create .dll for print.cpp as the following
>> g++ -shared -o print.dll print.obj
Now you need to create the .obj for main.cpp as the following
>> g++ -c main.cpp -o main.obj
Last step
>> g++ -o main.exe main.cpp print.dll