From owner-freebsd-questions Tue Mar 10 07:57:36 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id HAA16118 for freebsd-questions-outgoing; Tue, 10 Mar 1998 07:57:36 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from base486.home.org (imdave@imdave.pr.mcs.net [205.164.3.77]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id HAA16104 for ; Tue, 10 Mar 1998 07:57:29 -0800 (PST) (envelope-from imdave@mcs.net) Received: (from imdave@localhost) by base486.home.org (8.8.8/8.8.8) id JAA06721; Tue, 10 Mar 1998 09:57:17 -0600 (CST) Date: Tue, 10 Mar 1998 09:57:17 -0600 (CST) From: Dave Bodenstab Message-Id: <199803101557.JAA06721@base486.home.org> To: bsampley@best.com Subject: Re: GCC + object oriented prgm & FBSD Cc: questions@FreeBSD.ORG Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > From: Burton Sampley > > 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