0

Gud day,

Suppose I have these files:

hello.h
hello.cpp
main.cpp

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

$ g++ main.cpp -o main

not,

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

in the terminal..

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

3
Contributors
6
Replies
7
Views
9 Years
Discussion Span
Last Post by squinx22
0

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.

0

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...

0

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.....

0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.