1. 没有定义的符号

这类的错误, 解决办法A. 添加对应的头文件(源文件), B.前置声明

  • 1.1 错误描述:
 error: variable has incomplete type 'class XXX '
error: 'helper' is not a class, namespace, or enumeration
  • 1.2 编译器说的很清楚,没有找到其定义, 看看错误的代码
class _utils_api_ helper
{
public:
};
  • 1.3 错误提示:
[ 20%] Building CXX object CMakeFiles/calc.dir/src/utils.cpp.o
In file included from /home/xxx/demo/call_clang/src/utils.cpp:1:
/home/xx/demo/call_clang/include/utils.h:53:2: error: expected expression
public:
/home/cube/demo/call_clang/include/utils.h:51:20: error: variable has incomplete type 'class _utils_api_'
class _utils_api_ helper
^
/home/xx/demo/call_clang/include/utils.h:51:8: note: forward declaration of 'utils::_utils_api_'
class _utils_api_ helper
^
/home/xx/demo/call_clang/src/utils.cpp:14:14: error: 'helper' is not a class, namespace, or enumeration
std::string helper::wstr2str(const std::wstring& wstr)
  • 1.4 分析,这里提示,没有定义_utils_api_, 而用_utils_api_修饰了类helper
  • 1.5 解决: 增加对_utils_api_的定义。
  • 1.6 扩展, 可能没有包含头文件就已经在使用头文件中的函数或者类型,也会出现这样的错误,解决: 增加头对应的类型引用

2. C++特有的与C一起编译

  • 2.1 错误:
In file included from /home/xxx/demo/call_clang/src/utils.cpp:1:
/home/xxx/demo/call_clang/include/utils.h:149:3: error: templates must have C++ linkage
template<typename T>
^~~~~~~~~~~~~~~~~~~~
/home/xxxxxx/demo/call_clang/include/utils.h:42:2: note: extern "C" language linkage specification begins here
extern "C" {
^
/home/xxxxxx/demo/call_clang/include/utils.h:167:3: error: templates must have C++ linkage
template<typename T>
^~~~~~~~~~~~~~~~~~~~
/home/xxxxxx/demo/call_clang/include/utils.h:42:2: note: extern "C" language linkage specification begins here
extern "C" {

重要的是这句提示

error: templates must have C++ linkage
  • 2.2 提示说: 模板是C++ 才有的,而我的代码是:
#ifdef __cplusplus
extern "C" {
#endif //! __cplusplus class helper
{
public:
template<T>
std::string to_str(T & val)
{
return std::to_string(val);
}
}; #ifdef __cplusplus
}
#endif //! __cplusplus

代码中使用模板使用extern "C"尝试兼容C语言,当然不行,C没有模板

最新文章

  1. ajax+php+mysql 实现点赞、局部刷新,每个IP只能对一篇文章点赞一次
  2. 第九章 springboot + mybatis + 多数据源 (AOP实现)(转载)
  3. (源码)自己写的ScrollView里套漂亮的圆角listview(算是漂亮吧。。。)
  4. android 中 listview 设置自动匹配高度
  5. ios 5
  6. jmeter接口测试之登录测试
  7. bzoj1965 [Ahoi2005]SHUFFLE 洗牌
  8. Largest Rectangle in Histogram 解答
  9. WebSocket API
  10. php intval()和floatval()
  11. SAP MM 明明有需求,为啥MRP RUN后没有PR单据产生?
  12. Codeforces.871D.Paths(莫比乌斯反演 根号分治)
  13. | 线段树-地平线horizon
  14. 结构型---代理模式(Proxy Pattern)
  15. springboot项目打成war包
  16. 深度学习原理与框架-Tfrecord数据集的读取与训练(代码) 1.tf.train.batch(获取batch图片) 2.tf.image.resize_image_with_crop_or_pad(图片压缩) 3.tf.train.per_image_stand..(图片标准化) 4.tf.train.string_input_producer(字符串入队列) 5.tf.TFRecord(读
  17. Deep learning with Python 学习笔记(10)
  18. 尚学堂java答案解析 第三章
  19. ASP.NET中常用输出JS脚本的类(来自于周公博客)
  20. cut的用法【转】

热门文章

  1. 解决mac电脑耳机/外放突然无声音
  2. Zabbix源码安装,使用service命令管理zabbix进程
  3. MEGA软件——系统发育树构建方法(图文讲解) 转载
  4. SQL-用到的数据库语句总结
  5. KeepAlived双主模式高可用集群
  6. 学习java的第十一天
  7. day02 Rsyuc备份服务器
  8. oralce 存储过程传入 record 类型的参数?
  9. static JAVA
  10. Does compiler create default constructor when we write our own?