gpt4 book ai didi

未找到 C 结构类型(包括库),错误 "unknown type name"

转载 作者:行者123 更新时间:2023-11-30 14:36:59 25 4
gpt4 key购买 nike

我没有找到一个非常简单问题的解决方案。

文件“commons.h”:

struct test_struct{
int a;
}

文件“work.c”:

#include "commons.h"
void myfunction(test_struct this_is_a_test){
// ....
}

我做什么:

gcc commons.c -c -o commons.o    (no errors)
gcc work.c -c -o work.o ( "unknown type name "test_struct")

我做错了什么?

我还有另一个 .c,其中包含“commons.h”,编译一切正常,只有 work.c 出现错误。

最佳答案

您的头文件仅定义struct test_struct,而不是test_struct。您需要一个 typedef,这样您就可以引用它,而无需先说 struct

typedef struct test_struct {
int a;
} test_struct;

或者更改work.c以使用struct

void myfunction(struct test_struct this_is_a_test) {
//...
}

关于未找到 C 结构类型(包括库),错误 "unknown type name",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57682210/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com