【发布时间】:2015-12-21 07:27:59
【问题描述】:
好的,我所有的文件都是这样的
sendmail.h 在这个文件中声明了一些函数和一些常量
#define STMP_SERVER "smtp.exmail.qq.com"
#define LOGIN_NAME "secbot@test.com"
#define LOGIN_PASSOWRD "123456"
#define MAIL_TO "root@test.com"
char* get_local_addr(char* buf, size_t len);
int base64_encode(unsigned char *buf, int nLen, char *pOutBuf, int nBufSize);
void sendemail(char *smtpServer, char *serveruser, char *serverpassword, char *serverip);
int open_socket(struct sockaddr *addr);
sendmail.c 有一些类似于 sendmail.h 的功能
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include <unistd.h>
#include <sys/time.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <fcntl.h>
#include <stddef.h>
..............
test.c 是主函数
#include "sendmail.h"
#define SERVERNAME "root"
#define SERVERPASSWORD "123456"
int main()
{
sendemail(STMP_SERVER, SERVERNAME, SERVERPASSWORD,NULL);
return 0;
}
但是编译错误然后说这个
[root@ops test]# gcc -o test test.c
In file included from test.c:1:
sendmail.h:10: error: expected declaration specifiers or ‘...’ before ‘size_t’
sendmail.h:16: warning: ‘struct sockaddr’ declared inside parameter list
sendmail.h:16: warning: its scope is only this definition or declaration, which is probably not what you want
test.c: In function ‘main’:
test.c:10: error: ‘NULL’ undeclared (first use in this function)
test.c:10: error: (Each undeclared identifier is reported only once
test.c:10: error: for each function it appears in.)
【问题讨论】:
-
a) 使用正确的大小写 b) 包括 important 和 relevant 代码 c) 这意味着您多次声明了相同的函数(相同的名称) .
-
一般来说,你不应该让预处理器包含
*.c文件。
标签: c compiler-errors