Date: Tue, 10 Mar 1998 09:57:17 -0600 (CST) From: Dave Bodenstab <imdave@mcs.net> To: bsampley@best.com Cc: questions@FreeBSD.ORG Subject: Re: GCC + object oriented prgm & FBSD Message-ID: <199803101557.JAA06721@base486.home.org>
next in thread | raw e-mail | index | archive | help
> From: Burton Sampley <bsampley@best.com> > > I need some help trying to compile my first object-oriented program using > multiple files in C++ on FreeBSD. What syntax would make g++ happy? > GCC/G++ keep puking when I try to compile the "main" program with all of > the function calls to functions defined for the class as undefined > symbols. Here's the output from my most recent attempt with my code: > > bsampley(123)% g++ strcomp.C > /var/tmp/cc0017691.o: Undefined symbol `_get_data__11comparetypePc' > referenced from text segment > /var/tmp/cc0017691.o: Undefined symbol `_compare__11comparetype' > referenced from text segment > /var/tmp/cc0017691.o: Undefined symbol `_output__11comparetypePc' > referenced from text segment > bsampley(124)% It looks like you're missing the ``-c'' argument on the g++ command line. Read the man page for ``cc'', and try: g++ -c file1.C g++ -c file2.C g++ -c file3.C g++ -o my-first-prog file1.o file2.o file3.o ./my-first-prog Without the ``-c'' option, you are telling g++ to compile *and link*. What you probably want to do is compile each source file separately. You do this using ``g++ -c ...''. This creates an *object* file for each source file. When you've got each source file compiled and have the corresponding object file, you then link the object files together and create the final executable program file. > What I have tried: > > 1. Quickly searched through /usr/src/ looking for a good example of a C++ > program split into severals files. I couldn't locate one. > > 2. RTFM'ed the man pages for GCC/G++. I'll try this again, it has to be > in there somewhere. It's in here, but you may not be familiar with the terminology. > 3. Typed my professor's example program (all three files) kept getting > the same error I get with my code. > > 4. Tried the list. > > Thanks in advance for any help. Dave Bodenstab imdave@mcs.net To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199803101557.JAA06721>