[英]struct in header compilation error
I'm trying to write a framework library which wraps MPI.我正在尝试编写一个包装 MPI 的框架库。
I have a header file for the framework call afw.h
and an implementation file for the framework called afw.c
.我有一个框架调用
afw.h
的 header 文件和一个名为afw.c
的框架的实现文件。
I would like to be able to write application code which uses the framework by doing #include "afw.h"
in the application code.我希望能够通过在应用程序代码中执行
#include "afw.h"
来编写使用该框架的应用程序代码。
An excerpt from afw.h
: afw.h
的摘录:
#ifndef AFW_H
#define AFW_H
#include <mpi.h>
struct ReqStruct
{
MPI_Request req;
};
ReqStruct RecvAsynch(float *recvbuf, FILE *fp);
int RecvTest(ReqStruct areq);
I provide an implementation for RecvAsynch
in afw.c
which #includes afw.h
我在
afw.c
中提供了RecvAsynch
的实现,其中#includes afw.h
When I compile using mpicc
(an MPI compiler wrapper in this case using pgc underneath):当我使用
mpicc
编译时(在本例中使用下面的 pgc 的 MPI 编译器包装器):
mpicc -c afw.c -o afw.o
I get:我得到:
PGC-S-0040-Illegal use of symbol, ReqStruct (./afw.h: 69)
PGC-W-0156-Type not specified, 'int' assumed (./afw.h: 69)
PGC-S-0040-Illegal use of symbol, ReqStruct (./afw.h: 71)
PGC-W-0156-Type not specified, 'int' assumed (./afw.h: 71)
and similar errors wherever ReqStruct
is used in afw.c
以及在
ReqStruct
中使用afw.c
的任何地方的类似错误
Any ideas what I am doing wrong?知道我做错了什么吗?
You defined a struct ReqStruct
, not ReqStruct
, and those are not the same thing.您定义了一个
struct ReqStruct
,而不是ReqStruct
,它们不是一回事。
either change the function to将 function 更改为
struct ReqStruct RecvAsynch(float *recvbuf, FILE *fp);
or use typedef:或使用 typedef:
typedef struct ReqStruct ReqStruct;
In C++, the sequence:在C++中,序列:
struct ReqStruct
{
MPI_Request req;
};
defines a type ReqStruct
that you can use in your function declaration.定义一个
ReqStruct
类型,您可以在 function 声明中使用它。
In C, it does not (it defines a type struct ReqStruct
that you can use);在C中,它没有(它定义了一个你可以使用的类型
struct ReqStruct
); you need to add a typedef
such as:您需要添加一个
typedef
,例如:
typedef struct ReqStruct
{
MPI_Request req;
} ReqStruct;
Yes, the struct
tag can be the same as the typedef
name.是的,
struct
标签可以与typedef
名称相同。 Or you can use struct ReqStruct
in place of just ReqStruct
everywhere;或者您可以在任何地方使用
struct ReqStruct
代替ReqStruct
; I'd use the typedef
in preference.我会优先使用
typedef
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.