编译出错cstring问题

[复制链接]
查看11 | 回复9 | 2021-1-27 06:45:36 | 显示全部楼层 |阅读模式
请问,我用的编译器gcc4.4.5-6
error:'strlen'wasnotdeclaredinthisscope
总是出现这个问题,我在网上查了下说是要加#include
但是加了之后就出现这个问题
fromhash.cpp:2:
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:76:error:'::memchr'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:77:error:'::memcmp'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:78:error:'::memcpy'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:79:error:'::memmove'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:80:error:'::memset'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:81:error:'::strcat'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:82:error:'::strcmp'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:83:error:'::strcoll'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:84:error:'::strcpy'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:85:error:'::strcspn'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:86:error:'::strerror'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:87:error:'::strlen'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:88:error:'::strncat'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:89:error:'::strncmp'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:90:error:'::strncpy'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:91:error:'::strspn'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:92:error:'::strtok'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:93:error:'::strxfrm'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:94:error:'::strchr'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:95:error:'::strpbrk'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:96:error:'::strrchr'hasnotbeendeclared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:97:error:'::strstr'hasnotbeendeclared
我是用的automake生成的工程代码,如果写了一个测试文件
#include
intmain()
{
char*xx="dsdf";
strlen(xx);
return1;
}
这样编译又没问题
百思不得其解
请问这是什么问题啊?
分 -->
回复

使用道具 举报

千问 | 2021-1-27 06:45:36 | 显示全部楼层
你用g++编译吧,CString明显是C++头文件

回复

使用道具 举报

千问 | 2021-1-27 06:45:36 | 显示全部楼层
是的,我是用g++编译的
回复

使用道具 举报

千问 | 2021-1-27 06:45:36 | 显示全部楼层
有可能是头文件包含顺序产生了不良影响,把hash.cpp的代码上全或者试着调整#include的包含位置,看看问题会不会消失。
回复

使用道具 举报

千问 | 2021-1-27 06:45:36 | 显示全部楼层
#ifndefHASH_H
#defineHASH_H
#include
#include
#include
#include
#include
#include
#include
usingnamespacestd;

回复

使用道具 举报

千问 | 2021-1-27 06:45:36 | 显示全部楼层
把#include放在所有include最后面试一下,或者索性你就#include吧。
回复

使用道具 举报

千问 | 2021-1-27 06:45:36 | 显示全部楼层
不行啊,我放到最后也一样是这个错误,
换成string.h干脆
hash.cpp:Infunction'unsignedinthash4(constvoid*,unsignedint)':
hash.cpp:39:error:'strlen'wasnotdeclaredinthisscope
直接找不到strlen了
回复

使用道具 举报

千问 | 2021-1-27 06:45:36 | 显示全部楼层
我也遇到了这个问题,敢问LZ解决了吗?方便传授下经验吗?

回复

使用道具 举报

千问 | 2021-1-27 06:45:36 | 显示全部楼层
把预编译的结果打出来排查一下原因。
gcc/g++可以在命令行上加-E-dD输出预编译结果。
回复

使用道具 举报

千问 | 2021-1-27 06:45:36 | 显示全部楼层
偶遇到类似问题都是用
“每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。”
的方法解决的。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

主题

0

回帖

4882万

积分

论坛元老

Rank: 8Rank: 8

积分
48824836
热门排行