memset头文件 linux,error: ‘memset’ was not declared in this scope

http://blog.sina.com.cn/s/blog_79d599dc0100r2vz.html

昨天一同事把代码准备重新全新布置到新的环境上去的时候,代码报错了,先开始报错如下:

error: ‘memset’ was not declared in this scope

error: ‘strcat’ was not declared in this scope

首先想到的肯定是头文件未包含进来。但不可能,因为这套代码已经在其它环境上编译过N次啦,不可能代码里面没有添加对头文件的包含啊。

于是想到是否是因为新环境里面include目录下没有对应的头文件呢?还或是include目录在这个环境下变了呢?不是/usr/include下面啦。

经过一查,上面两个都不是。

这个时候就有点郁闷啦。把环境按以前的都设置一遍,还是一样。没办法啦。只好放今天来重新查查啦。

今天早上来,可能时间也比较充足,所以慢慢来。既然报这个错误,那我把这个头文件再添加到.h代码里面呢?

然后发现添加一个,某个错误就能编译过去。看来还真是头文件的问题。

但接下来还有其他几个警告,如下:

test.cpp:213: warning: ignoring return value of ‘int system(const char*)’, declared with attribute warn_unused_result

test.cpp: In member function ‘int test::load(std::string&)’:

test.cpp:58: warning: deprecated conversion from string constant to ‘char*’

test.cpp:58: warning: deprecated conversion from string constant to ‘char*’

test.cpp:58: warning: deprecated conversion from string constant to ‘char*’

test.cpp:58: warning: deprecated conversion from string constant to ‘char*’

test.cpp:58: warning: deprecated conversion from string constant to ‘char*’

test.cpp:94: warning: suggest explicit braces to avoid ambiguous ‘else’

test.cpp:61: warning: ignoring return value of ‘int pipe(int*)’, declared with attribute warn_unused_result

居然这些还报,一一为这些没有判断函数返回值的作了修改。编译通过。

然后就想为什么这个系统要求这么严格呢?查一下GCC的版本,如下:

以前旧环境:

gcc 版本 4.1.2 20070626 (Red Hat 4.1.2-14)

现在的新环境:

gcc version 4.4.5 (Ubuntu/Linaro 4.4.4-14ubuntu5)

原来是GCC版本不同。所以想GCC新版本对代码的这些要求现在越来越严格啦。还有函数的一些检查项,还有编译时候MAKEFILE里面对库文件的引用。

具体是否是因为这个严格的原因,没有去详细查GCC的文档。但猜想是这样吧。

以后如果代码里面对某个函数的头文件还是尽量包含进来吧,至少不是什么坏事。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值