0

サードパーティのライブラリを.cファイルに含めようとしていますが、同じ名前の typedef 構造体があるため、再定義または競合する型のエラーが発生します。

SOでいくつかの回答を読んだ後、ガードを含めようとしましたが、.hファイルのtypedefを明らかに直接変更すると問題が解決しました。

(関数の戻り値の型も変更する必要があります)

// stack.h
typedef struct item stack_item;

// queue.h
typedef struct item queue_item;

ただし、元のコードは次のとおりです。

// stack.h
typedef struct item item;

// queue.h
typedef struct item item;

次のエラーがスローされます。

In file included from test.c:5:0:
Queues/queue.c:6:8: error: redefinition of ‘struct item’
 struct item {
        ^

In file included from Stacks/stack.c:4:0, from test.c:4:
Stacks/stack.h:6:16: note: originally defined here
 typedef struct item item;
                ^

.hファイルの定義を変更する代わりに、これを解決する標準的な方法を知りたい

4

1 に答える 1