常见的编译错误
来源:互联网 发布:linux 统计登录次数 编辑:程序博客网 时间:2024/05/01 18:22
以下是在平常的实践中出现的编译错误
1、undefined reference问题总结
a、 链接时缺失了相关目标文件(.o)
b、 链接时缺少相关的库文件(.a/.so)
c、链接的库文件中又使用了另一个库文件
同样,如果我们的库或者程序中引用了第三方库(如pthread.a)则同样在链接的时候需要给出第三方库的路径和库文件,否则就会得到undefinedreference的错误。
d、多个库文件链接顺序问题
我们需要注意,在链接命令中给出所依赖的库时,需要注意库之间的依赖顺序,依赖其他库的库一定要放到被依赖库的前面,这样才能真正避免undefinedreference的错误,完成编译链接。
E、.h文件声明函数,.cpp定义这些函数
包含.h文件,然后编译
声明和定义函数参数不一致
声明:bool ceph_argparse_flag(std::vector<const char*>&args,
std::vector<constchar*>::iterator &i, ...)
定义:
bool ceph_argparse_flag(std::vector<const char*> &args,
std::vector<const char*>::iterator i, ...)
错误点:
没有加入&引用,注意要仔细对比检查声明和定义部分。
e、 在c++代码中链接c语言的库出错
没有使用extern “c”来标记
f、使用const对象访问非const方法导致编译器报错
error:passing ‘const ECBackend::OverwriteInfo’ as ‘this’ argument of‘std::_Rb_tree_iterator<std::pair<const long unsigned int,std::pair<long unsigned int, long unsigned int> > >ECBackend::OverwriteInfo::end()’ discards qualifiers
g、默认参数,在定义中重复指定,只需要在声明语句中指定
/usr/src/hj/PingAn/src/cluster/cluster_pool.cpp:1659:error: default argument given for parameter 3 of ‘intClusterPool::cc_list(Json::Value, int, std::string)’
/usr/src/hj/PingAn/src/cluster/cluster_pool.hpp:93:error: after previous specification in ‘int ClusterPool::cc_list(Json::Value,int, std::string)
h、error:static member function cannot have cv-qualifier
解答:A static member function shall not be declared const
, volatile
, or constvolatile
.static
functions haveno this
parameter. They need no cv-qualifiers.
i、error: invalid use of incomplete type ‘structJson::LogicError’
使用了只声明没有定义的类型
j、error:template with C linkage (c++程序被声明为c类型链接)
objclass/class_api.cc:In function 'int cls_cxx_map_set_vals(cls_method_context_t, conststd::map<std::basic_string<char>, ceph::buffer::list>*)':
objclass/class_api.cc:589:104:error: taking address of temporary [-fpermissive]
r =cls_cxx_setxattr(hctx, iter->first.c_str(),&(static_cast<bufferlist>(iter->second)));
这个并没有解决问题,将bufferlist *转换为const bufferlist *是非法的操作
bufferlistin_bl(iter->second);
cls_cxx_setxattr(hctx,iter->first.c_str(), &in_bl);
- 常见的编译错误
- 常见的c编译错误
- 常见的C++编译错误
- 常见的vc++编译错误
- 常见的vc++编译错误
- 编译内核的常见错误
- Qt编译常见的错误:
- iOS 编译常见的错误
- Qt的常见编译错误
- 常见的vc++编译错误
- 常见的20种vc++编译错误
- configure编译中常见的错误
- .configure编译中常见的错误
- ubuntu下编译qt的常见错误
- 编译时产生常见的连接错误
- 编译时JAVA最常见的错误
- 编译Launcher2出现的常见错误
- ubuntu下编译qt的常见错误
- 【web】上机实验一
- web开发模式+三层架构与MVC
- HTML 4.01的标准和规范以及如何使用中文
- python库
- Filter Initiated I/O
- 常见的编译错误
- Android 从源码角度分析消息处理机制(Handler,Looper,Message)
- 单链表-用尾插法创建单链表
- msysGit 安装后的配置
- VS2008 F5或Debuging Run 重新编译整个工程
- Codeforces Round #373 (Div. 2) E. Sasha and Array
- Sql基础练习03
- ubuntu下php5.6安装pcntl扩展
- 去哪儿网笔试题分析