模板链接问题(多重定义) [英] Template linking problem (multiple definition)

查看:88
本文介绍了模板链接问题(多重定义)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好!


我们正在为实时应用程序开发一个数学库,并希望使用一些给定的数学库作为基础(ipp,MTL ,. 。)我们的库是一个

包装器,你可以通过模板参数选择底层的

库。因此我们将库分成两个

命名空间:


第一个定义名称空间全局函数,它们调用

baselibrary功能。这些是模板功能,其中一些是b / b
用于双倍和浮动的。


第二个定义类,其中第一个函数是
名称空间将被调用。


现在出现了问题:如果我将我们的数学库包含在两个

编译单元中,链接器会给出一个错误,其中包含:


A.lo:函数Namespace1 :: ns_globalfunction:

A.lo:ns_globalfunction的多重定义

B.lo:首先定义这里


这适用于每个spezialition的第一个

命名空间的每个namespaceglobal模板函数。


问候,

Georg

解决方案




Georg Teichtmeister写道:

你好!

我们正在为实时应用程序开发一个数学库,并希望使用一些给定的数学库作为基础(ipp,MTL,..) 。我们的库是那些的包装器,你应该能够通过模板参数选择底层的库。因此,我们将库分成两个名称空间:

第一个定义名称空间全局函数,它们调用
baselibrary函数。这些是模板函数,其中包括double和float的一些说明。

第二个定义类,其中第一个
命名空间的函数将被调用。
编译单元中,链接器会给出一个错误:

A.lo:在函数Namespace1 :: ns_globalfunction:
A.lo:ns_globalfunction的多重定义
B.lo:首先在这里定义

这适用于每个spezialition的第一个命名空间的每个namespaceglobal模板函数。



对不起,忘了提我使用gcc-2.95.3和gcc-3.2




Georg Teichtmeister < TE *********** @ emt.tugraz.at>在消息中写道

news:3F ************** @ emt.tugraz.at ...

你好!

我们正在开发一个用于实时应用程序的数学库,并希望使用一些给定的数学库作为基础(ipp,MTL,..)。我们的库是那些的包装器,你应该能够通过模板参数选择底层的库。因此,我们将库分成两个名称空间:

第一个定义名称空间全局函数,它们调用
baselibrary函数。这些是模板函数,其中包括double和float的一些说明。

第二个定义类,其中第一个
命名空间的函数将被调用。
编译单元中,链接器会给出一个错误:

A.lo:在函数Namespace1 :: ns_globalfunction:
A.lo:ns_globalfunction的多重定义
B.lo:首先在这里定义

这适用于每个spezialition的第一个命名空间的每个namespaceglobal模板函数。

问候,
Georg




您是否内联了完全专业化的功能?即


模板< typename T>

void f(T x)

{

...

}


模板<>

inline void f< double>(double x)

{

...

}


john


您是否内联了完全专业化的功能?即

模板< typename T>
void f(T x)
{
...
}

模板<>
内联void f< double>(双x)
{
...
}




不,我这样写:

模板< typename T>

void f(T x)

{

...

}


模板<>

void f(double x)

{

...

}


Hello!

We are developing a math - library for realtime applications and want to
use some given mathlibraries as base(ipp, MTL, .. ). Our library is a
wrapper for those and you should be able to select the underlying
library by template parameter. Therefore we split up our library in two
namespaces:

The first one defines namespace-global functions which call the
baselibrary functions. These are templatefunctions which some
spezialitions for double and float.

The second one defines classes, where the functions of the first
namespace will be called.

Now comes the problem: If I include our mathlibrary into two
compilationunits the linker gives a error which says:

A.lo:in function Namespace1::ns_globalfunction:
A.lo:multiple definition of ns_globalfunction
B.lo:first defined here

And this comes for every namespaceglobal template function of the first
namespace for every spezialition.

regards,
Georg

解决方案



Georg Teichtmeister wrote:

Hello!

We are developing a math - library for realtime applications and want to
use some given mathlibraries as base(ipp, MTL, .. ). Our library is a
wrapper for those and you should be able to select the underlying
library by template parameter. Therefore we split up our library in two
namespaces:

The first one defines namespace-global functions which call the
baselibrary functions. These are templatefunctions which some
spezialitions for double and float.

The second one defines classes, where the functions of the first
namespace will be called.

Now comes the problem: If I include our mathlibrary into two
compilationunits the linker gives a error which says:

A.lo:in function Namespace1::ns_globalfunction:
A.lo:multiple definition of ns_globalfunction
B.lo:first defined here

And this comes for every namespaceglobal template function of the first
namespace for every spezialition.



sorry, forgot to mention that I use gcc-2.95.3 and gcc-3.2



"Georg Teichtmeister" <te***********@emt.tugraz.at> wrote in message
news:3F**************@emt.tugraz.at...

Hello!

We are developing a math - library for realtime applications and want to
use some given mathlibraries as base(ipp, MTL, .. ). Our library is a
wrapper for those and you should be able to select the underlying
library by template parameter. Therefore we split up our library in two
namespaces:

The first one defines namespace-global functions which call the
baselibrary functions. These are templatefunctions which some
spezialitions for double and float.

The second one defines classes, where the functions of the first
namespace will be called.

Now comes the problem: If I include our mathlibrary into two
compilationunits the linker gives a error which says:

A.lo:in function Namespace1::ns_globalfunction:
A.lo:multiple definition of ns_globalfunction
B.lo:first defined here

And this comes for every namespaceglobal template function of the first
namespace for every spezialition.

regards,
Georg



Did you inline the fully specialised functions? I.e.

template <typename T>
void f(T x)
{
...
}

template <>
inline void f<double>(double x)
{
...
}

john



Did you inline the fully specialised functions? I.e.

template <typename T>
void f(T x)
{
...
}

template <>
inline void f<double>(double x)
{
...
}



no, i write it like that:
template <typename T>
void f(T x)
{
...
}

template <>
void f(double x)
{
...
}


这篇关于模板链接问题(多重定义)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆