gpt4 book ai didi

c项目编译错误

转载 作者:行者123 更新时间:2023-11-30 21:24:49 25 4
gpt4 key购买 nike

好的,我所有的文件都是这样的

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.)

最佳答案

  1. 停止在 a.c 中使用类似 #include "sendmail.c" 的内容
  2. 创建一个头文件,其中包含sendmail.c中函数的声明
  3. #include 来自 a.c头文件

关于c项目编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34390782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com