编译出错cstring问题

han4235 2013-02-19 09:27:57
请问, 我用的编译器gcc 4.4.5-6
error: 'strlen' was not declared in this scope
总是出现这个问题, 我在网上查了下 说是要加#include <cstring>
但是加了之后就出现这个问题
from hash.cpp:2:
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:76: error: '::memchr' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:77: error: '::memcmp' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:78: error: '::memcpy' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:79: error: '::memmove' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:80: error: '::memset' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:81: error: '::strcat' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:82: error: '::strcmp' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:83: error: '::strcoll' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:84: error: '::strcpy' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:85: error: '::strcspn' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:86: error: '::strerror' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:87: error: '::strlen' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:88: error: '::strncat' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:89: error: '::strncmp' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:90: error: '::strncpy' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:91: error: '::strspn' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:92: error: '::strtok' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:93: error: '::strxfrm' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:94: error: '::strchr' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:95: error: '::strpbrk' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:96: error: '::strrchr' has not been declared
/usr/lib/gcc/x86_64-redhat-linux/4.4.5/../../../../include/c++/4.4.5/cstring:97: error: '::strstr' has not been declared

我是用的automake生成的工程代码, 如果写了一个测试文件
#include <cstring>

int main()
{

char *xx = "dsdf";
strlen(xx);
return 1;
}

这样编译又没问题
百思不得其解
请问这是什么问题啊?
...全文
1865 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-11-09
  • 打赏
  • 举报
回复
偶遇到类似问题都是用 “每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。” 的方法解决的。
fefe82 2015-11-06
  • 打赏
  • 举报
回复
把预编译的结果打出来排查一下原因。 gcc / g++ 可以在命令行上加 -E -dD 输出预编译结果。
qq_16135483 2015-11-06
  • 打赏
  • 举报
回复
我也遇到了这个问题,敢问LZ解决了吗?方便传授下经验吗?
han4235 2013-02-19
  • 打赏
  • 举报
回复
不行啊, 我放到最后也一样是这个错误, 换成string.h 干脆 hash.cpp: In function 'unsigned int hash4(const void*, unsigned int)': hash.cpp:39: error: 'strlen' was not declared in this scope 直接找不到strlen了
ri_aje 2013-02-19
  • 打赏
  • 举报
回复
把 #include <cstring> 放在所有 include 最后面试一下,或者索性你就 #include <string.h> 吧。
han4235 2013-02-19
  • 打赏
  • 举报
回复
#ifndef HASH_H #define HASH_H #include <cstring> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <malloc.h> #include <assert.h> #include <math.h> using namespace std;
ri_aje 2013-02-19
  • 打赏
  • 举报
回复
有可能是头文件包含顺序产生了不良影响,把 hash.cpp 的代码上全或者试着调整 #include <cstring> 的包含位置,看看问题会不会消失。
han4235 2013-02-19
  • 打赏
  • 举报
回复
是的, 我是用g++编译的
xiaoyaoxiaonizi 2013-02-19
  • 打赏
  • 举报
回复
你用g++编译吧,CString明显是C++头文件
/** 名称: CESock类 功能: 多线程方式实现简单易用的套接字,使用TCP协议 阻塞方式. 最大发送数据字节数不宜超过1KB. 同时实现了客户端及服务器端功能,可接收及发送数据. 版本: v1.0.0 第一版本发布时间: 20100823 第一作者: Jef 第一作者电子邮箱: dungeonsnd@126.com 版权: 您可以免费修改及使用,但把本程序(及修改后)用于商业用途前请得到第一作者的许可。 版本修改记录: v1.0.0 20100823 第一版本 新建类,多线程阻塞套接字.在Windows XP下用VC++6.0编译运行正确. 未在Unicode下测试. 使用: 1. 调用这个类通常不用修改头文件中的宏,注意每次发送数据字节数不要超过1024. 2. 在接收数据的处实现消息WM_RECVDATA的响应函数. 在MFC中的头文件添加如下代码, afx_msg void OnRecvData(WPARAM wParam,LPARAM lParam); 在MFC中的实现文件添加如下代码, ON_MESSAGE(WM_RECVDATA,OnRecvData) void CCommunicationView::OnRecvData(WPARAM wParam,LPARAM lParam) { CString str=(char*)lParam; //接收到的消息. CString strFrom=(char*)wParam; //发送消息的IP地址. ...... } 3. 调试时保留 #define SHOW_ERROR_MSGBOX,如果运行时出错将弹出对话框. 注释掉此行时如果出错将不做处理. 建议发布软件时(即Release版)注释此行代码. 4. 建议不要在函数内部定义CESock类型变量. 5. 建议此模块作为底层通信,上层应实现传输协议,如大文件分段传输、发送及反馈消息。 **/

33,311

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 新手乐园
社区管理员
  • 新手乐园社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧