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没有模板

Linux c++编译总结(持续更新)的更多相关文章

  1. Linux 服务器命令,持续更新……

    记录一下常用命令给自己备忘备查,会持续更新-- 一.查看和修改Linux的时间 1. 查看时间和日期,命令: date 2.设定时间和日期 例如:将系统日期修改成2020年2月14日12点的命令: d ...

  2. Linux 常用指令【持续更新】

    在学校的时候学过一些简单的 Linux 命令,主要是文件的创建拷贝解压等操作,最近在电脑上安装了一个CentOS6.8版本的基本版,纯命令行操作. ../ 代表上一级目录 ./ 代表本级目录 / 代表 ...

  3. 软件测试工程师的Linux之路(持续更新修正)

    软件测试工程师成长必经之路—Linux学习. 测试工程师不同于运维工程师,所以在对不熟悉Linux的测试人员来说,先了解一些Linux系统的基本操作,能顺利开展测试工作即可,在强迫自己使用,熟悉命令行 ...

  4. Linux常用命令(持续更新)

    lsb_release -a 查看linux操作系统信息 getconf LONG_BIT 查看linux操作系统位数 useradd [-g groupname] username 创建用户,并指定 ...

  5. Linux常用指令(持续更新)

    (这些文章都是从我的个人主页上粘贴过来的,大家也可以访问我的主页 www.iwangzheng.com) PP真的是一位很有姿势的程序猿,有这样的邻居真好,榜样啊. pwd 当前路径 df  -kh ...

  6. linux术语解析(持续更新)

    1.linux内核有个版本,分别是 longterm: 提供长期支持的内核版本 stable: 稳定版本 Beta 测试版

  7. Linux 特殊指令总结(持续更新)

    Linux 命令 1. 查看系统信息 1.uname uname (1) - print system information uname (2) - get name and information ...

  8. linux相关命令大全......持续更新

    启动项目8080端口被占用,然而老久没玩Linux,命令忘光了,杀死进程都不记得了. 决定整理一波吧....... Linux: sudo强制执行,不在root用户下时使用. top 相当于windo ...

  9. 超赞的Linux软件分享(持续更新)

    开发 Android studio - Android 的官方 IDE:Android Studio 提供在各种类型的安卓设备上构建应用最快的工具. Aptana - Aptana Studio 利用 ...

  10. Linux下常用命令(持续更新)

    l: 列举目录下的所有文件 ll: 显示详细属性 pwd: 查看当前所在完整路径 cd: 变更文件夹(变更到根目录:cd + /:变更到上级目录:cd + ..) sudo: 允许利用超级用户权限执行 ...

随机推荐

  1. 解决 VS Code 无法使用Ctrl+C等快捷键

    背景 VScode 安装 Vim扩展后,无法使用Ctrl+C,Ctrl+X和 Ctrl+V等热键 解决方案 方案一 停用Vim 热键覆盖 # 原因: vim 扩展默认启用Vim ctrl键覆盖常见的V ...

  2. js ajax 请求

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. R语言与医学统计图形-【10】ggplot2图形映射

    ggplot2绘图系统--图形映射 颜色的映射. #aes中映射变量 ggplot()+geom_point(aes(x=carat,y=price,color='blue'),#color视为单一变 ...

  4. ZAQI

    mysql> CREATE TABLE emploee ( -> name CHAR(64) NOT NULL, -> email CHAR(64), -> password ...

  5. Hive-insert into table 与 insert overwrite table 区别

    区分insert into 和 insert overowrite: 0. 命令格式 INSERT OVERWRITE|INTO TABLE tablename [PARTITION (partcol ...

  6. oracle中char],varchar,varchar2

    VARCHAR.VARCHAR2.CHAR的区别 1.CHAR的长度是固定的,而VARCHAR2的长度是可以变化的, 比如,存储字符串"abc",对于CHAR (20),表示你存储 ...

  7. 日常Java 2021/9/19

    Math类方法 package m; public class m { public static void main(String args[]) { //计算平方根 System.out.prin ...

  8. A Child's History of England.20

    CHAPTER 7 ENGLAND UNDER HAROLD THE SECOND, AND CONQUERED BY THE NORMANS Harold was crowned King of E ...

  9. 数据库SQL性能优化

    1.in与exists的效率比较 in是把外表和内表作hash 连接,而exists 是对外表作loop 循环,每次loop 循环再对内表进行查询.一直以来认为exists 比in 效率高的说法是不准 ...

  10. Linux基础命令---host域名查询工具

    host host是一个常用的DNS查询工具,经常用来查询域名.检查域名解析是否正确. 此命令的适用范围:RedHat.RHEL.Ubuntu.CentOS.Fedora.   1.语法       ...