スタック オーバーフローに関するよくある質問ですが、私の場合は奇妙で、適切な回答が見つからなかったので、まだ投稿しています。
これは大規模なプロジェクトですが、この問題のために含まれているファイルは、types.h、glob.h、test.c、test.h、および main.c の 5 つだけです。
types.hで、構造体を定義するとします。
struct s_foo {
int a;
};
glob.hで
struct s_foo *foo;
test.hで
#ifndef GLOB_H
#define GLOB_H
extern struct s_foo *foo;
#endif
test.cで
#include "types.h"
#include "test.h"
struct s_foo *foo = NULL;
main.cで
#include "types.h"
#include "test.h"
...
foo = (struct s_foo *)malloc(sizeof(struct s_foo));
このプログラムは gcc でコンパイル可能で、問題なく動作しますが、Eclipse によって、main.c でシンボル「foo」を解決できないという厄介なエラーが表示されます。
Eclipse でこのエラーが発生する理由を誰か教えてください。これは、変数 foo が複数定義されているためでしょうか?
ありがとう!