typedefされた構造体がファイルで宣言されています。それへのポインタがあり、グローバル変数として複数のファイルで使用したいと思います。誰かが私が間違っていることを指摘できますか?
fileA.h:
typedef struct
{
bool connected;
char name[20];
}vehicle;
extern vehicle *myVehicle;
fileA.c:
#include "fileA.h"
void myFunction(){
myVehicle = malloc(sizeof(vehicle));
myVehicle->connected = FALSE;
}
fileB.c:
#include "fileA.h"
void anotherFunction(){
strcpy(myVehicle->name, "this is my car");
}
私が得るエラーは次のとおりです。
fileAで参照される未定義の外部「myVehicle」