This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Template linker errors with gcc 4.6.3


On 4 November 2013 15:07, David Aldrich wrote:
> Hi
>
> We have a mature project that builds fine with gcc 4.4, but when we build it with gcc 4.6.3 on Ubuntu 12.04 LTS  we get linker errors that are related to templates.

Are you using the same linker version in both cases?  That might be as
significant as the compiler version.


> I am finding it difficult to understand the errors.  As a general question, was template processing significantly changed between gcc 4.4 and 4.6 in a way that might cause linker errors?

Not that I can think of.

> Here is an example of an error that I am getting:
>
> + make
> g++ -o _gnuRelease/myapp -Wl,-whole-archive,-export-dynamic ../Kernel/_gnuRelease/libKernel.a    -lboost_python-mt-py27 -lpython2.7 -Wl,--no-whole-archive -ldl
> ../Kernel/_gnuRelease/libKernel.a(EVD.o): In function `eigSymmetric(Matrix<double> const&, Matrix<double>&, Matrix<double>&, unsigned int)':
> EVD.cpp:(.text+0x25a): undefined reference to `Matrix<double>::eye(unsigned int, double)'

How is EVD.o compiled?

> Now, the only line of code in eigSymmetric() that calls eye() is:
>
>     int N = a_X.numRows();
>     ...
>     a_V = Matrix<double>::eye(N);
>
> so I don't understand why the linker is looking for `Matrix<double>::eye(unsigned int, double)' rather than for `Matrix<double>::eye(int)'.

At a guess, maybe because the function is declared as something like
Matrix<T>::eye(unsigned, double = 0.0)
i.e. just because you pass the function an int doesn't mean that's
what the function is declared to take.


> There are also many other errors:
>
> EVD.cpp:(.text+0x1c6e): undefined reference to `Matrix<std::complex<double> >::Matrix()'
> EVD.cpp:(.text+0x1c7d): undefined reference to `Matrix<double>::Matrix()'
> EVD.cpp:(.text+0x1f9e): undefined reference to `Matrix<std::complex<double> >::Matrix(unsigned int, unsigned int, std::vector<std::complex<double>, std::allocator<std::complex<double> > > const&, MatrixConst::EOrdering)'
> EVD.cpp:(.text+0x1fe5): undefined reference to `Matrix<std::complex<double> > operator*<std::complex<double> >(Matrix<std::complex<double> > const&, Matrix<std::complex<double> > const&)'
> EVD.cpp:(.text+0x2006): undefined reference to `Matrix<std::complex<double> > operator-<std::complex<double> >(Matrix<std::complex<double> > const&, Matrix<std::complex<double> > const&)'
> EVD.cpp:(.text+0x2080): undefined reference to `Matrix<std::complex<double> >::frob2() const'
> <snip>

It looks like every member of Matrix is missing.

Either the file EVD.o is compiled with -fno-implicit-templates or
those functions are not defined in EVD.cpp

Function templates must either be defined in every file that uses them
or explicitly instantiated.

But you haven't provided nearly enough information to know what the
specific problem is in your case.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]