编译两个c文件不起作用,找不到 header

标签 c compilation

当尝试从终端编译两个 c 文件时,我遇到了问题。 我的文件是:main.c user_info.c。它们都在同一个文件夹中。 尝试编译时,我使用:gcc main.c user_info.c -o program 它给出的错误消息如下: ma​​in.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/

相关文章:

c - 将 sqlite3_column_text() 返回到文字字符串

c - 被误解的代码示例

windows - 在 Windows 上编译 Erlang 代码

ASP.NET 部署 : How to avoid losing session state when updating code?

c - C程序中的段错误(核心转储)错误

c - 如何初始化指向结构的指针数组?

c - 多线程程序中的段错误

java - 解决方案: NoClassDefFoundError when dynamically compiling code

objective-c - 我将如何在 Ubuntu 上使用 Objective-C ParseKit 编译项目?

java - 这是编译或反编译的副作用吗?