You need to use the
export
keyword. However, I don't think G++ has proper support, so you need to include the template function's definition in the header so the translation unit can use it. This is because the
<int>
'version' of the template hasn't been created, only the
<typename T>
'version.'
An easy way is to
#include
the .cpp file. However, this can cause problems, e.g. when other functions are in the .cpp file. It will also likely increase the compile time.
A clean way is to move your template functions into its own .cpp file, and include that in the header
or
use the
export
keyword and compile it separately.
c++中template不支持声明和实现分别放在不同的文件中。可以通过include cpp文件解决这个问题。
分享到:
相关推荐
C生成静态库给C++调用出现undefined reference to ...解决方案 已经写好makefile,还有头文件,看注释,基本没问题的
直到查阅到类似情况:https://forums.xilinx.com/t5/Embedded-Development-Tools/SDK-undefined-reference/td-p/818300 发现我的工程的问题是gcc 链接时找不到库文件,如下图我在gcc链接命令中添加了 -llwip4 (该...
【转】undefined reference to错误的解决方法.doc
内核编译出现 undefined reference to `__gnu_mcount_nc'问题的补丁包
undefined reference to ‘pthread_create’undefined reference to ‘pthread_join’ 问题原因: pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,...
解决Android下getifaddrs和freeifaddrs undefined reference 的问题,即android下的c实现
调用ffmpeg库函数,实现播放视频,编译时img_convert函数出错,提示找不到,是因为版本问题。新版本的ffmpeg添加了新的接口:libswscale来处理图像缩放。
解决 INFO: /usr/lib64/libstdc++.so.5: undefined reference to `memcpy@GLIBC_2.14',将文件替换到/usr/lib64就可解决问题(源文件记得备份)
在运行KalmanFilter的时候需要用到...main.cpp:(.text+0x1eb): undefined reference to cv::KalmanFilter::KalmanFilter(int, int, int, int)' main.cpp:(.text+0x245): undefined reference tocv::Mat::zeros(int
/opt/QtSDK/Desktop/Qt/474/gcc/lib/libQtGui.so:-1: 错误:undefined reference to `FT_Library_SetLcdFilter'
undefined reference to 'pthread_create'的解决方法,需要的朋友可以参考一下
编译时出现undefined reference to `SetPduPowerConsumptionCnt'错误要如何解决呢?有没有什么好的解决方法?下面小编就为大家解答吧,如果你也遇到了这种情况,可以过来参考下
针对前几天,用busybox编译根文件的时候,碰到的问题和解决方法进行总结
问题:程序模型用C++语言编写,在程序模型和调用函数之间添加了一个接口文件modelc.cpp,用来让用c语言程序调用程序模型中的函数; 新添加了两个函数setPduPowerConsumptionCnt()和setPduPowerConsumptionTot(),...
linux内核2.6cache源代码,很详细的源代码,给linux学习带来狠多参考
//usr/lib64/libstdc++.so.5:对‘memcpy@GLIBC_2.14’未定义的引用 glibc-static-2.17-55.el7.x86_64.rpm (网上解决),我提供的是glibc-static-2.17-55.el6.x86_64.rpm相关包解决
因为客户出于服务器安全的角度进行了漏洞扫描,爆出openssh的问题,所以进行研究并修复。一般都是直接升级到最新版的软件,但是要根据实际情况进行判断,一般没什么问题
文件包含了使用GoogleBreakpad捕获崩溃文件需要的文件,包括lib及头文件,可以看我的博客里介绍了如何使用GoogleBreakpad生成dump文件,来分析程序崩溃原因。