Gud day,

Suppose I have these files:


in what directory will I put the hello.o and hello.hpp so that I will only type

$ g++ main.cpp -o main


$ g++ main.cpp hello.cpp -I. -o main.cpp

in the terminal..

thanks.... I will highly appreciate youre response....

put them all in the same directory as main.cpp. The compiler default is to put them in the current working directory. You can confirm that yourself by compiling a program then listing out the files in that directory.

Actually, you will still have to do the following to be able to compile and link 'main':

$ g++ -c hello.cpp -I.

Then only can you do:

$ g++ -o main main.cpp hello.o

You can try creating an archive (libhello.a) and put that in /usr/lib or /usr/local/lib before doing:

$ g++ -o main main.cpp -lhello

Hope this helps...

I mean, in what folder in the /usr directory should I put the object file of the compiled hello.cpp so that I can use that in many programs.. By the way, I am creating a library... And where will I put the hello.h as well. thanks for the reply.....

thank you very much for the reply, but I dont want to specify its location when I compile the main function in the terminal.

I would like to add it in the gcc library so that it would be easier for me to inherit the implementation whenever I want not specifying its location during the compilation of the main functions.

Hoping to here from you soon..... thanx again

This article has been dead for over six months. Start a new discussion instead.