[oclug] g++ linking question
gfranks at home.com
Sat Jan 27 17:17:47 EST 2001
>>>>> "James" == James Leigh <james.leigh at ottawa.com> writes:
James> fellas, I am having the darndest time trying to use g++ and
James> compile a simple program. In the past I have always
James> started with one cpp file and included anything I needed,
James> but as programs get bigger this method causes problems.
James> Now I want to compile objects and link them together.
James> I have a main.cpp a header file and a class definition
James> file. When I try to run g++ on the two cpp files is spits
James> out the same errors as if all I was compiling was the
James> main.cpp. Here is some shell output to help explain what
James> is going on.
James> $ g++ main.cpp /tmp/ccTLJBe1.o: In function `main':
James> /tmp/ccTLJBe1.o(.text+0x21): undefined reference to
James> `Smartptr<char>::Smartptr(char *)'
James> /tmp/ccTLJBe1.o(.text+0x30): undefined reference to
***DANGER WILL ROBINSON***
You are using templates. G++ is really, really stupid when it comes
to these beasts. Look up the *info* pages (you do use emacs, don't
you), and start reading up.
Otherwise, use a real compiler.
(NB: Gcc is a rather good compiler, which is paradoxically unreleated
Long answer. G++ does not know how to do template instantiation
automatically, so you have to supply it hints (most other c++
compilers do this automatically). G++ has lots of different ways of
supplying these hints, so I am afraid you are going to have to read
the documenatation and choose the method that suites you best.
__@ Greg Franks <| _~@ __O
_`\<,_ Ottawa, Ontario, Canada |O\ -^\<;^\<,
(*)/ (*) (*)--(*)%---/(*)
"Where do you want to go today?" Outside.
More information about the OCLUG