我尝试从终端编译两个c文件时遇到问题。我拥有的文件是:main.c user_info.c。它们都在同一个文件夹中。尝试编译时,我使用:gcc main.c user_info.c -o program它给出如下错误消息:main.c:3:10:致命错误:找不到'user_info.h'文件
main.c
#include <stdio.h>
#include <stdlib.h>
#include "user_info.h"
int main() {
struct user person1;
struct user person2;
person1.userId = 1;
person2.userId = 2;
puts("Enter the first name of user 1");
gets(person1.firstName);
puts("Enter the first name of user 2");
gets(person2.firstName);
printf("User 1 id is %d\n", person1.userId);
printf("User 2 first name is %s\n", person2.firstName);
return 0;
}
user_info.c
struct user {
int userId;
char firstName[25];
char lastName[25];
int age;
float weight;
};
您有user_info.c而不是user_info.h。如果要定义结构,请将user_info.c的名称更改为user_info.h,然后尝试编译main.c。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句