在MSVC C DLL中导出模板类的模板成员函数
Exporting templated member function of a templated class in MSVC C++ DLL
我正在编译PCL库(https://github.com/pointCloudlibrary/pcl.git)中,以在我自己的项目中使用。这是一个大量使用C 模板的项目。为了减少编译时间,我将PCL_NO_PRECOMPILE
设置为OFF
,这意味着该实现不在标题文件中。我的应用程序只能使用编译PCL时已实例化的类和功能。
问题是,在MSVC DLL中未导出模板类的模板成员函数。我正在使用MS Visual Studio 2017社区版。这是特定的问题。
我正在创建pcl::Hough3DGrouping
的子类,该类别在https://github.com/pointcloudlibrary/pcl/pcl/master/master/recognition/include/include/pcl/recognition/cg/hough_3d.h。感兴趣的具体功能是在第510行文件底部定义的受保护函数computeRf()
。当我查看DLL中的导出符号时,我看不到computeRf()
。因此,我无法从我的自定义代码中使用它。
我以为computeRf()
没有在DLL中导出,因为它已模板。因此,我尝试在https://github.com/pointcloudlibrary/pcl/blob/master/master/recognition/src/src/cg/hough_3d.cpp中尝试了显式实例化。特别是我添加了
template void pcl::Hough3DGrouping<pcl::PointXYZRGB, pcl::PointXYZRGB, pcl::ReferenceFrame, pcl::ReferenceFrame>::computeRf<pcl::PointXYZRGB, pcl::ReferenceFrame>(const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >, pcl::PointCloud<pcl::ReferenceFrame>)
在https://github.com/pointCloudlibrary/pcl/blob/master/master/Recognition/src/cg/cg/hough_3d.cpp中的第44行上
编译时,我会收到错误:
E:libspclsrcrecognitionsrccghough_3d.cpp(45): error C3190: 'void pcl::Hough3DGrouping<pcl::PointXYZRGB,pcl::PointXYZRGB,pcl::ReferenceFrame,pcl::ReferenceFrame>::computeRf(const boost::shared_ptr<const pcl::PointCloud<PointT>>,pcl::PointCloud<PointModelRfT>)' with the provided template arguments is not the explicit instantiation of any member function of 'pcl::Hough3DGrouping<pcl::PointXYZRGB,pcl::PointXYZRGB,pcl::ReferenceFrame,pcl::ReferenceFrame>'
with
[
PointT=pcl::PointXYZRGB,
PointModelRfT=pcl::ReferenceFrame
]
我的目标是在我的应用程序中创建pcl::Hough3DGrouping
的子类,并从中调用基类的computeRf()
。我唯一需要的实例是:
pcl::Hough3DGrouping<pcl::PointXYZRGB, pcl::PointXYZRGB, pcl::ReferenceFrame, pcl::ReferenceFrame>
pcl::Hough3DGrouping<pcl::PointXYZRGB, pcl::PointXYZRGB, pcl::ReferenceFrame, pcl::ReferenceFrame>::computeRf<pcl::PointXYZRGB, pcl::ReferenceFrame>
我应该如何使用最小的更改对PCL源代码?
模板不能从dll中导出。
复制粘贴您尝试导出的内容和签名:
template<typename PointType, typename PointRfType> void
computeRf
(const boost::shared_ptr<const pcl::PointCloud<PointType> > &input, pcl::PointCloud<PointRfType> &rf)
template void
pcl::Hough3DGrouping<pcl::PointXYZRGB, pcl::PointXYZRGB, pcl::ReferenceFrame, pcl::ReferenceFrame>::
computeRf<pcl::PointXYZRGB, pcl::ReferenceFrame>
(const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >, pcl::PointCloud<pcl::ReferenceFrame>)
我注意到有所不同。您试图导出一些函数参数不是参考的内容。模板类的模板方法具有参考函数参数。
编译器说"这些不匹配"。我会相信的。
进行参数参考,它将与类中的方法匹配。
template void
pcl::Hough3DGrouping<pcl::PointXYZRGB, pcl::PointXYZRGB, pcl::ReferenceFrame, pcl::ReferenceFrame>::
computeRf<pcl::PointXYZRGB, pcl::ReferenceFrame>
(const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB> >&, pcl::PointCloud<pcl::ReferenceFrame>&)
您在Instantiation系列中有两个错误:
-
hough3dgrouping模板参数顺序是错误的,应为
pcl::PointXYZRGB, pcl::ReferenceFrame, pcl::PointXYZRGB, pcl::ReferenceFrame
而不是
pcl::PointXYZRGB, pcl::PointXYZRGB, pcl::ReferenceFrame, pcl::ReferenceFrame
-
您在参数列表中忘记了
&
s:computeRf(const boost::shared_ptr<const pcl::PointCloud<pcl::PointXYZRGB>>&, pcl::PointCloud<pcl::ReferenceFrame>&)
不需要
computeRf
的模板参数,因为扣除有效。
- 对RValue对象调用的LValue ref限定成员函数
- 为什么使用 "this" 指针调用派生成员函数?
- 将公共但非静态的成员函数与ALGLIB集成
- 使用指向成员的指针将成员函数作为参数传递
- 将重载的成员函数传递给函数模板
- 我不小心调用了一个没有自己类对象的成员函数.但这是怎么回事呢
- 如何在C++中使用非静态成员函数作为回调函数
- C++错误C2600:无法定义编译器生成的特殊成员函数(必须首先在类中声明)
- 关联容器的下界复杂性:成员函数与非成员函数
- 在 C++ 中用派生类型重写成员函数
- 链表的泛型函数remove()与成员函数remove)
- 如何将lambda作为模板类的成员函数参数
- constexpr构造函数需要常量成员函数时出现问题
- 将自由函数绑定为类成员函数
- 区分非成员函数和头文件中的成员函数
- 如何从子成员函数修改父公共成员变量
- 保留对其他类的成员函数的引用
- 在运算符重载定义中使用成员函数(const错误)
- 内联如何影响模块接口中的成员函数
- 将成员函数指针作为参数传递给模板方法