C - 在使用 make 编译时,主要类型和以前的 main 定义冲突



我正在尝试将三个文件编译在一起,在passweb.c中有一个主要方法。

这里通过网络.c

#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <cipher.c>
#include <menu.c>
long pointer;
char *createRecord(char *name, char *password, char *type);
char *file = "password.csv";
int main(int argc, char *argv[]){
    if(fopen(file,"r")==NULL){
        FILE *newFile = fopen(file,"w+");
        fclose(newFile);
    }
    if(strcmp(argv[0],"-menu")==1){
        menu();
    }
    else if(strcmp(argv[0],"-add")==1){
        add(argv[1], argv[2], argv[3]);
    }
    else if(strcmp(argv[0],"-edit")==1){
        edit(argv[1],argv[2],argv[3],argv[4],argv[5],argv[6]);
    }
}

和密码.c

#include <stdio.h>
#include <stdlib.h>
int Encrypt(char *fileName){
    int offset=5;
    Shift(fileName, offset);
}
int Decrypt(char *fileName){
    int offset=-5;
    Shift(fileName, offset);
}

生成文件:

passweb: passweb.c menu.c cipher.c
      gcc -o passweb passweb.c menu.c cipher.c -I.

错误:

passweb.c:10: error: conflicting types for ‘main’
./cipher.c:3: error: previous definition of ‘main’ was here

我不知道我做错了什么。提前感谢您的时间!!

不要将源文件包含在源文件中。摆脱以下情况:

#include <cipher.c>
#include <menu.c>

编写它的方式,你正在编译menu.c和cipher.c两次。首先在编译 passweb.c 时,然后在编译 menu.c 和 cipher.c 时再次编译。

最新更新