【发布时间】:2014-08-15 10:42:12
【问题描述】:
我有一个我不明白的错误。如果我只是将包含放在 mail.c 文件而不是 mail.h 文件中,我可以摆脱错误。我的代码如下所示:
mail.h 文件:
#ifndef MAIL_H
#define MAIL_H
//Normal needed headers
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//Custom headers
#include "pop3.h"
#include "pasw.h"
#include "rese.h"
#define NAME_SIZE 100 //Defines the length of e.g. the user name
#define PASSW_SIZE 100 //Defines the length of the password
#define ADD_SPACE 10 //Defines some additional space for arrays
#define HELPTEXT "help.txt" //Defines the name of the help.txt file
enum bool {true, false};
typedef enum bool bool;
#endif
pop3.h 文件:
#ifndef POP3
#define POP3
// Open SSl headers
#include <openssl/bio.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
//Needed for the password input to not show the password
#include <termios.h>
//Normal needed headers
#include <stdio.h>
#include <string.h>
#include <ctype.h>
//Custom headers
#include "mail.h"
#include "pasw.h"
#include "rese.h"
void pop3(unsigned char *, unsigned char *, unsigned char *);
int GetUserPassw(unsigned char *, unsigned char *);
int login(BIO *, unsigned char *, unsigned char *, unsigned char *, bool, bool);
int GetUsername(unsigned char *;);
int GetInput(unsigned char*, int);
int GetNumberOfMessages(BIO *);
void RetrieveEmail(BIO *);
#endif
在邮件中。 c 我已经包含了 mail.h,并且在 pop3.c 中我已经包含了 pop3.h。我得到的错误是:
gcc -lcrypto -lssl -c mail.c
In file included from mail.h:10:0,
from mail.c:11:
pop3.h:24:69: error: unknown type name ‘bool’
int login(BIO *, unsigned char *, unsigned char *, unsigned char *, bool, bool);
^
pop3.h:24:75: error: unknown type name ‘bool’
int login(BIO *, unsigned char *, unsigned char *, unsigned char *, bool, bool);
^
Makefile:12: recipe for target 'mail.o' failed
make: *** [mail.o] Error 1
我的 Makefile 看起来像这样:
CC=gcc
CFLAGS=-lcrypto -lssl -o
OFLAGS=-lcrypto -lssl -c
RM=rm -i
all: mail
mail: mail.o pop3.o pasw.o rese.o
$(CC) $(CFLAGS) mail mail.o pop3.o pasw.o rese.o
mail.o: mail.c
$(CC) $(OFLAGS) mail.c
pop3.o: pop3.c
$(CC) $(OFLAGS) pop3.c
pasw.o: pasw.c
$(CC) $(OFLAGS) pasw.c
rese.o: rese.c
$(CC) $(OFLAGS) rese.c
clean:
rm *.o mail
在我稍微更改文件结构之前,它已经奏效了。但是我可以通过将包含“命令”从 mail.h 中放入 mail.c 中来解决这个问题。
期待收到您的来信。
国王的问候, 绿化
【问题讨论】:
-
不要试图定义你自己的
bool类型,而是包含<stdbool.h>。 -
这里没有“文件类型”。
-
顺便说一句
CFLAGSOFLAGS -
非常感谢。 :-)