Q:

Linking libraries in GCC

there are some files that I am trying to compile in ubuntu using makefile. 
I have added the following lines in my makefile after several searches on web.
run: hellocode.cpp    
    g++ -c hellocode.cpp -lssl -lcrypto

Still while compiling it creates the object files and then throws this error:
undefined reference to 'SSL_write'....
on the contrary if remove the '-c' and use it like this
run: hellocode.cpp         
    g++ hellocode.cpp -lssl -lcrypto

Then I dont see the previous errors of linking but it shows different errors not related to openssl linking but related to other files in the code. I have already browsed through many questions on this forum related to this none seem to have helped me in this.
Kindly tell me whether my makefile is wrong or is there some problem with my machine that its not able to link to my library. 

A:

Here's a simple Makefile that you could adopt. Note that compilation and linking are 2 steps. If needed you can use -I for additional include paths and -L for additional link paths.
.PHONY : all 
all : hellocode

hellocode : hellocode.o 
    g++ -o hellocode hellocode.o -lssl -lcrypto

hellocode.o : hellocode.cpp
    g++ -c hellocode.cpp -o hellocode.o

Here are some basics of makefiles if it helps.

