首页 > c程序编译出错,求教怎么回事

c程序编译出错,求教怎么回事

首先是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里定义了一些函数

    #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>
    
    static char base64_table[64] =
    {
        'A', 'B', 'C', 'D', 'E', 'F', 'G',
        'H', 'I', 'J', 'K', 'L', 'M', 'N',
        'O', 'P', 'Q', 'R', 'S', 'T',
        'U', 'V', 'W', 'X', 'Y', 'Z',
        'a', 'b', 'c', 'd', 'e', 'f', 'g',
        'h', 'i', 'j', 'k', 'l', 'm', 'n',
        'o', 'p', 'q', 'r', 's', 't',
        'u', 'v', 'w', 'x', 'y', 'z',
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
        '+', '/'
    };
    
    
    //int base64_encode(unsigned char *buf, int nLen, char *pOutBuf, int nBufSize);
    
   省略若干代码

之后再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.)


把include的所有头文件全部放在.h里面,或者在test.c里面重新引用一次


请问你看报错信息了么?

sendmail.c里的所有include语句 全部挪到seamail.h里面试试

【热门文章】
【热门文章】