This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
templated cmath function instantiation
- To: gcc at gcc dot gnu dot org
- Subject: templated cmath function instantiation
- From: Kurt Garloff <garloff at suse dot de>
- Date: Wed, 20 Jun 2001 14:07:50 +0200
- Organization: TUE/NL, SuSE/FRG
Hi,
compiling my templated C++ numeric library with gcc-3.0.0, I use
-fno-implicit-templates to prevent multiple instantiations and explicitly
instantiate all the templates that are supposed to be in the library.
I stumbled across this:
../lina/bin-ix86/libtbcidouble.so: undefined reference to double
std::__cmath_power<double>(double, unsigned)'
I'm rather sure this is a bug: -fno-implicit-templates is not supposed to
change the underlying C++ std library, is it?
The compiler probably can't just ignore the flag for included C++ std
headers, but then, those symbols should be (weakly) present in libstdc++.so.
At least for the templates only used internally.
Testcase attached.
garloff@pckurt:~/Physics/numerix-2.0-gcc3/lina/test > g++ -o cmath_pow
cmath_pow.cc -fno-implicit-templates
/tmp/ccW0xLby.o: In function double std::__pow_helper<double>(double, int)':
/tmp/ccW0xLby.o(.gnu.linkonce.t._ZSt12__pow_helperIdET_S0_i+0x22): undefined
reference to double std::__cmath_power<double>(double, unsigned)'
/tmp/ccW0xLby.o(.gnu.linkonce.t._ZSt12__pow_helperIdET_S0_i+0x3f): undefined
reference to double std::__cmath_power<double>(double, unsigned)'
collect2: ld returned 1 exit status
If you define WORKAROUND, it works. gcc-2.95 also works, of course.
I'll submit a gccbug unless somebody explains to me that it's me that's
stupid not the compiler ...
Any chance we get that fixed until 3.0.1?
Regards,
--
Kurt Garloff <garloff@suse.de> Eindhoven, NL
GPG key: See mail header, key servers Linux kernel development
SuSE GmbH, Nuernberg, FRG SCSI, Security
/** cmath_pow.cc
*
* Trying to reproduce linking errors for
* double std::__cmath_power<double>(double, unsigned)
* in gcc-3.0.0, if -fno=implicit-templates is used.
* The flag also affects the internally used (invisible) templates
* from the C++ std library :-( and at least std::__cmath_power
* is missing from libstdc++.so.
*
* (c) Kurt Garloff, garloff@suse.de, 2001-06-20, GNU GPL
*
* Compile with g++ -o cmath_pow cmath_pow.cc -fno-implicit-templates
*
*/
#include <cstdlib>
#include <cstdio>
#include <cmath>
namespace testns {
template <typename T>
double our_pow (const T v, const int pw)
{
return std::pow ((double)v, pw);
};
};
// Explicitly instantiate (needed because -fno-implicit-templates)
namespace testns {
template double our_pow<long> (const long, const int);
};
int main (int argc, char* argv[])
{
long int arg = 2; int pw = 4;
if (argc >= 2)
arg = std::atol (argv[1]);
if (argc >= 3)
pw = std::atol (argv[2]);
long int res = (long int) testns::our_pow (arg, pw);
std::printf ("%li\n", res);
return 0;
}
// The problem ...
#ifdef WORKAROUND
template double std::__cmath_power<double>(double, unsigned);
#endif
PGP signature