[英]Compiling two c files not working, header not found
我在尝试从终端编译两个 c 文件时遇到问题。 我拥有的文件是:main.c user_info.c。 它们都在同一个文件夹中。 尝试编译时,我使用: gcc main.c user_info.c -o program它给出的错误消息为: main.c:3:10: fatal error: 'user_info.h' file not found
主文件
#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。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.