I have a simple structure in dbinfo.h viz.
typedef struct {
int fields;
} dbinfo;
In the main program I have:
#include <string.h>
...
#include "dbinfo.h"
extern dbinfo *tst_info;
void main() {
tst_info = (dbinfo *) calloc(1, sizeof(dbinfo));
dbinfo.fields = 3;
printf("\n number of fields = %d"), getnumflds());
...
}
In another file utilities.c I have
#include "dbinfo.h"
extern dbinfo *tst_info;
int getnumflds() {
return tst_info.fields;
}
When I try to link I get undefined symbols in utilities.c of tst_info. If I remove the extern then I get no unresolved symbols, but the value of fields is 0.
What am i doing wrong here?
I simply want to be able to use and change the value of 'fields' that was set in main in other functions compiled separately.
Been a long time since I used C and having trouble accessing those neurons!