Search code examples
cmpiheader-files

struct in header compilation error


I'm trying to write a framework library which wraps MPI.

I have a header file for the framework call afw.h and an implementation file for the framework called 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.

An excerpt from 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

When I compile using mpicc (an MPI compiler wrapper in this case using pgc underneath):

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

Any ideas what I am doing wrong?


Solution

  • You defined a struct ReqStruct, not ReqStruct, and those are not the same thing.

    either change the function to

    struct ReqStruct RecvAsynch(float *recvbuf, FILE *fp);
    

    or use typedef:

    typedef struct ReqStruct ReqStruct;