我在编译C++ UDP客户端程序时遇到了一个奇怪的编译器错误。C++编译器错误“未在此范围内声明”
g++ -o client Udp.cpp ClientMain.c -I. -lpthread
In file included from ClientMain.c:1:0:
Udp.h: In destructor ‘CUdpMsg::~CUdpMsg()’:
Udp.h:103:43: error: ‘free’ was not declared in this scope
Udp.h: In member function ‘void CUdpMsg::Add(in_addr_t, const void*, size_t)’:
Udp.h:109:34: error: ‘malloc’ was not declared in this scope
Udp.h:109:41: error: ‘memcpy’ was not declared in this scope
ClientMain.c: In function ‘int main(int, char**)’:
ClientMain.c:28:57: error: ‘memcpy’ was not declared in this scope
ClientMain.c:29:61: error: ‘printf’ was not declared in this scope
ClientMain.c:30:17: error: ‘stdout’ was not declared in this scope
ClientMain.c:30:23: error: ‘fflush’ was not declared in this scope
ClientMain.c:34:68: error: ‘printf’ was not declared in this scope
ClientMain.c:35:17: error: ‘stdout’ was not declared in this scope
ClientMain.c:35:23: error: ‘fflush’ was not declared in this scope
ClientMain.c:37:30: error: ‘usleep’ was not declared in this scope
我在我的cpp文件的开头声明了以下内容。
#include <netinet/in.h>
#include <netdb.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <ifaddrs.h>
#include <net/if.h>
#include <cstdlib>
#include <string>
#include <stdlib.h>
#include <cstring>
#include <errno.h>
像“的memcpy”函数应该string.h中声明......我把它(和字符串和CString的)所有申报,而我仍然得到这些编译器错误。有没有人有线索为什么会发生这种情况?谢谢。
你说你在你的*“cpp”*文件中包含这些内容,但错误在'ClientMain.c'中(注意'.c',而不是'.cpp')? –
我想你需要在'UDP.h'中包含这些文件中的一部分 – Djole
是你为这个函数调用的std命名空间 – triclosan