table pointer in header file for use with multiple source files

Hi all, I'm rather new at these forum things, so sorry in advance if I post this at the wrong place or if it has already been answered.

Here is my problem. I need to place a pointer to a structure type table in a header file, then, in a source file A that includes the header, create the dynamic table using "malloc". It must then be accessible from another source file B:

Here's what I tried so far with no success:

Header.h:

#ifndef FLAG
#define FLAG

typedef struct{
int a;
int b;
}T_config ;

extern T_config *Tab_config;

void test();

#endif


Source file A.cpp:

#include"header.h"

void main()
{
int i;

test();

for(i=0;i<9;i++){
Tab_config[i].a = i;
Tab_config[i].b = i;
}
}


Source file B.cpp:

#include"header.h"

void test()
{
T_config *Tab_config;

Tab_config = (T_config *) malloc(10 * sizeof(T_config));
}


With this structure I get a an two error messages when building:
1. error LNK2001: unresolved external symbol "struct T_config * Tab_config"
2. error LNK2019: unresolved external symbol "struct T_config * Tab_config"referenced in function _main

Also, I read that it is recommended to "free" a dynamic table once we're done with it, in this case, where would the free(Tab_config) go, at the end of the main function, or the test function.

Any help would be appreciated, thank you
Last edited on
Topic archived. No new replies allowed.