This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
c++ template instantiation problem on MAC OSX
- To: gcc-help at gcc dot gnu dot org
- Subject: c++ template instantiation problem on MAC OSX
- From: Maria Lando <mlando at watchpointmedia dot com>
- Date: Tue, 26 Jun 2001 12:22:28 -0400
- Organization: WatchPoint Media
Mac c++ compiler is based on the 2.95.2 gcc version, however templates
doesn't appear to work in the same way. Did anyone have any similar
experience?
Here is an example of the code that links to the template function
(plus) in the library.
---------------------------------------------------
#include <stdio.h>
#include <plus.h>
int main(int argc, const char *const argv[])
{
int y=10, x=5;
int z = plus(x,y);
fprintf(stderr,"z=%d\n",z);
}
-----------------------------------------------------
Linking error:
make test
c++ -c -I. -I/usr/local/include -g -Wall -ftemplate-depth-20 -O2 test.c
c++ -o test test.o lib.a -L/usr/local/lib -ldat -lstdc++
/usr/bin/ld: Undefined symbols:
_plus__H1Zi_RCX01n1_i make: *** [test] Error 1
Here is the library lib.a:
file plus.h
-----------------------------------
#pragma interface
#include <string.h>
#include <stdio.h>
template <class T> T plus(const T& a, const T& b);
---------------------------------------------------
file plus.c
-------------------------------------------------
#include "plus.h"
#pragma implementation
template <class T> T plus(const T& a, const T& b) { return a + b; }
template int plus(const int&, const int&);
int main(int argc, const char *const argv[])
{ plus(10,10);
}
----------------------------------------------------
Library is compiled using the following command and compilation is seems
to be OK:
c++ -c -I. -I/usr/local/include -g -Wall -ftemplate-depth-20 -O2 plus.c
rm -f lib.a
libtool -static -o lib.a -s plus.o
Thanks,
-Maria