From: "Her, Il" <il.her@hp.com>
To: Ian Lance Taylor <iant@google.com>
Cc: "gcc-help@gcc.gnu.org" <gcc-help@gcc.gnu.org>
Subject: RE: Undefined reference to template function ...
Date: Wed, 01 Jun 2011 01:03:00 -0000 [thread overview]
Message-ID: <7758AFD4380CD24F86D3266E0D083A0550544AFE4D@GVW1160EXB.americas.hpqcorp.net> (raw)
In-Reply-To: <mcrhb8brna9.fsf@coign.corp.google.com>
Yes, it is compiled well with gcc 3.4.6,
but it doesn't work with gcc 4.1.2
thank you
Her, Il
Technology Consulting
Technology Service Korea
TEL : +82-2-2199-4475
Mobile : +82-10-4765-5597
il.her@hp.com
-----Original Message-----
From: Ian Lance Taylor [mailto:iant@google.com]
Sent: Tuesday, May 31, 2011 10:51 PM
To: Her, Il
Cc: gcc-help@gcc.gnu.org
Subject: Re: Undefined reference to template function ...
"Her, Il" <il.her@hp.com> writes:
> Thank you for answering my question.
> Here is my sample.
>
> [Test.h]
> #ifndef __TEST_hh
> #define __TEST_hh
> struct TEST
> {
> int a, b;
> };
> #endif
>
> [sub.h]
> #include <stdio.h>
> template <typename T> struct Base
> {
> void dump(T &r);
> int fn(int a, int b);
> };
>
> [sub.cpp]
> #include "sub.h"
>
> template<typename T> void Base<T>::dump(T &r)
> {
> }
>
> template<typename T> int Base<T>::fn(int a, int b);
> {
> return 0;
> }
>
> [main.cpp]
> #include <stdio.h>
> #include "sub.h"
> #include "TEST.h"
>
> int main()
> {
> Base<TEST> t;
> TEST x;
>
> t.dump(x);
> t.fn(1, 2);
> }
>
> ** Result of compiling
> [test@test-1] $ g++ -c -dynamic sub.cpp
> [test@test-1] $ g++ -shared -o libsub.so sub.o
> [test@test-1] $ g++ -g -W -o main main.cpp -lsub -L./
> /tmp/ccaUlqlQ.o: In function `main`:
> /home/guinsa/main.cpp:10: undefined reference to `Base<TEST>::dump(TEST&)`
> /home/guinsa/main.cpp:11: undefined reference to `Base<TEST>::fn(int, int)`
> collect2: ld returned 1 exit status
In your earlier message you said that you had code that worked with gcc
3.4.6 but failed with gcc 4.1.2. Does this test case work with gcc
3.4.6?
Ian
next prev parent reply other threads:[~2011-06-01 1:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-05-30 8:32 Her, Il
2011-05-31 8:53 ` Ian Lance Taylor
2011-05-31 12:21 ` Her, Il
2011-05-31 12:44 ` Axel Freyn
2011-05-31 15:29 ` Ian Lance Taylor
2011-06-01 1:03 ` Her, Il [this message]
2011-06-01 8:45 ` Axel Freyn
2011-06-01 13:23 ` Ian Lance Taylor
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7758AFD4380CD24F86D3266E0D083A0550544AFE4D@GVW1160EXB.americas.hpqcorp.net \
--to=il.her@hp.com \
--cc=gcc-help@gcc.gnu.org \
--cc=iant@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).