共享库中未使用的模板函数 [英] Unused template functions in shared library

查看:138
本文介绍了共享库中未使用的模板函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在用C ++编写的共享库中有一个模板函数(该函数在库中的任何位置都不被调用,因此不应该生成,我错了?)[g ++,Linux]

I have a template function in a shared library written in C++(the function is not called anywhere in the library, so it shouldn't be generated, am i wrong?) [g++, Linux]

我尝试在应用程序中使用这个模板函数,但编译器给出链接错误。我使用objdump搜索该函数,但我看不到.so
中的函数有一种方法解决这个问题?

I try to use this template function in the application but compiler gives link error.I searched the function using objdump but I can not see the function in the .so Is there a way to solve this problem?

推荐答案

编译器开发人员很难实现模板,因此,大多数C ++编译器实际上需要你模板代码在头文件中,甚至完整的类实现(有一些例外和技巧,以避免这种情况)。

Templates are hard to implement by compiler developers, and thus, most C++ compilers actually require you to put template code in header files, even complete class implementations (there are some exceptions and tricks to avoid this though).

对于你的情况,你需要做的是移动你的函数模板到头文件(可能带有其他函数模板),并在需要时导入。

For your case, all you need to do is move your function template to a header file (probably with other function templates) and import that when you need it.

希望有帮助。

这篇关于共享库中未使用的模板函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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