当尝试从终端编译两个 c 文件时,我遇到了问题。 我的文件是:main.c user_info.c。它们都在同一个文件夹中。 尝试编译时,我使用:gcc main.c user_info.c -o program 它给出的错误消息如下: main.c:3:10: fatal error :找不到“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;
}
用户信息.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。
关于编译两个c文件不起作用,找不到 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42147190/