Article View: gnu.gcc.help
Article #916Re: how can i tell if my new c++ compiler is working?
From: Steve E. Chapel
Date: Tue, 05 Sep 1995 08:14
Date: Tue, 05 Sep 1995 08:14
51 lines
2169 bytes
2169 bytes
bcc063@casbah.acns.nwu.edu (UNLISTED) writes:
>what do these errors mean i did or didn't do?
>/* this is the beginning of file String.h */
>const int max_string_length = 128;
>class String{
>public:
> void set_to(char*);
> int length();
> int read();
> void print();
>private:
> char text[max_string_length+1];
>};
>/* this is the end of file String.h */
>/* and the beginning of file test.cc */
>#include "String.h"
>#include<stdio.h>
>main(int, char *[])
>{
> String s, t;
> s.set_to("hello world");
> printf("Length of s is %d\n", s.length());
> printf("Enter string t: ");
> t.read();
> printf("Length of t is %d\n",t.length());
> return 0;
>}
>/* this is the end of file test.cc */
You never defined the member functions. You gave the declarations, but
never the definitions. This is what the linker is complaining about.
The compiler sees just the declarations and write the function calls,
assuming you will link in the called functions. But since you never gave
the definitions of the functions, the linker was not able to write
the machine code for the function calls.
You need a String.cc file that contains the definitions. It should #include
"String.h". You'll compile it separately from test.cc. Then you'll link
test.o and String.o (or whatever your object files are called).
By the way, the main(int, char *[]) is a new twist on an old theme.
I'd recommend int main(). Ignoring the argc and agrv arguments is okay.
--
Steve Chapel schapel@cs.ucsb.edu | http://www.cs.ucsb.edu/~schapel
Senior in Computer Science at the | finger -l schapel@eci1.ucsb.edu
University of California, Santa Barbara | Finger me for my PGP public key
Technical Details
Message-ID:
<42h0ss$mt7@zonker.cs.ucsb.edu>Path:
arc1-ca.pugleaf.net!nntp.ucsb.edu!not-for-mailReferences:
<42fktm$g2p@news.acns.nwu.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!nntp.ucsb.edu!not-for-mail From: schapel@zonker.cs.ucsb.edu (Steve E. Chapel) Newsgroups: gnu.gcc.help,comp.lang.c++,comp.unix.programmer Subject: Re: how can i tell if my new c++ compiler is working? Date: 5 Sep 1995 01:14:20 -0700 Organization: University of California, Santa Barbara Message-ID: <42h0ss$mt7@zonker.cs.ucsb.edu> References: <42fktm$g2p@news.acns.nwu.edu> NNTP-Posting-Host: zonker.cs.ucsb.edu