Andy Fan <zhihui.fan1213@gmail.com> writes:
> for example, when I want the LOCKTAG in .c file, which is defined in
> "storage/lock.h". then I wrote the code like this:
> #include "storage/lock.h"
> ...
> LOCKTAG tag;
> compile and get errors.
> In file included from
> .../src/include/storage/lock.h:21:
> /../../../src/include/storage/lockdefs.h:50:2: error: unknown type name
> 'TransactionId'
> TransactionId xid; /* xid of holder of
> AccessExclusiveLock */
The reason that's failing is that you didn't include postgres.h first.
The general expectation --- and we do mechanically verify this,
periodically --- is that any Postgres header should have enough #include's
that you can include it without further work, so long as you included
postgres.h (or postgres_fe.h, or c.h, depending on context) beforehand.
One of those three headers must be the first inclusion in every Postgres
.c file. There are portability reasons behind that rule, which you
don't really want to know about ;-) ... just do it like that.
regards, tom lane