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

by the way, I am using Ubuntu 6.06

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

you can put it anywhere you want -- there is no restriction. Just add the -L flag or specify the whole path in the .o filename.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.