Re: g++ linker error
Nugzar Nebieridze <nugzar@cyberjunkie.com> writes:
> Marcel Harkema wrote:
>
> > On Thu, Oct 14, 1999 at 12:28:47PM +0200, Oliver Bettinger wrote:
> > >
> > > I just installed Debian 2.1 and tried tu compile a small program with the
> > > g++ compiler. It worked. then I tried to write a Header file and a CPP file
> > > and compile it, so I could use the methods in there in other programs. Just
> > > to test, if it would work. Here are the files:
> > >
> > > HEADER:
> > > struct Test {
> > > void func();
> > > };
> > >
> > > CPP:
> > > #include "test.h"
> > > #include <iostream>
> > > using namespace std;
> > > void Test::func() {
> > > cout << "This function does absolutely nothing!\n";
> > > }
> > >
> > > Thats all.
> > > As I said g++ test.cpp
> > > my compiler returned:
> > > /usr/lib/crt1.o(.text+0x36): undefined reference to 'main'
> > > collect2: ld returned 1 exit status
> > >
> > > What went wrong??? HELP!!!
> >
> > I suggest you buy yourself a good C++ book, and read the manpage of gcc.
> > Anyway, you probably want to use 'g++ -c test.cpp' to compile to a .o file
> > instead of building an executable (you have no main function).
> >
> And more,
>
> in this example you must use "class" instead of "struct", structure does not
> support functions.
>
Go get a good C++ book too !
Phil.
Reply to: