This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: need to link 3 files...how?


Bruce Fisher wrote:
> 
> i have 3 files named:
> main.cpp
> person.cpp
> person.h
> 
> i've #included person.h in my main.cpp.
> how do i compile this to run. i know i have to link them together but i dont
> know how to do that. someone told me i would have to use "make". i read the
> mn pages on this but it really didnt help me out with understanding make.
> can anyone help?
> 
> thanks in advance

You're linking _two_ files, the result of compileing main.cpp and the
result of compiling person.cpp.

g++ -c main.cpp                        <==== this creates main.o
g++ -c person.cpp                      <==== this creates person.o
g++ -o <programname> main.o person.o   <==== this uses g++ to link them 
       ===========
       put whatever you want the program name to be in place of
<programname> above.

HTH,
--ag
-- 
Artie Gold, Austin, TX
mailto:agold@bga.com or mailto:agold@cs.utexas.edu
--
"If you come to a fork in the road, take it." L. P. Berra


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]