[英]Compiling two c files not working, header not found
I have a problem, when trying to compile two c files from terminal.我在尝试从终端编译两个 c 文件时遇到问题。 Files I have are: main.c user_info.c.
我拥有的文件是:main.c user_info.c。 They are both in the same folder.
它们都在同一个文件夹中。 When trying to compile, I use: gcc main.c user_info.c -o program It gives an error message as: main.c:3:10: fatal error: 'user_info.h' file not found
尝试编译时,我使用: gcc main.c user_info.c -o program它给出的错误消息为: main.c:3:10: fatal error: 'user_info.h' file not found
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用户信息.c
struct user {
int userId;
char firstName[25];
char lastName[25];
int age;
float weight;
};
You have user_info.c not user_info.h.你有 user_info.c 而不是 user_info.h。 If you are defining a structure, change the name of user_info.c to user_info.h and try compiling main.c.
如果您正在定义结构,请将 user_info.c 的名称更改为 user_info.h 并尝试编译 main.c。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.