P
PCHOME
Hello! I am working on dividing a single C file into several files.
Now I encounter a problem about the global variables
and can not find a way to solve it.
All global variables and codes used to be in that single file, that
worked OK. But when I divdie that file into several ones, I
have many "invalid use of undefined type" errors.
The four files are main.c, main.h, readLP.h, and readLP.c.
In readLP.h
I have:
#define MAX_NUMROWS 181010
#define MAX_NUMCOLS 201
#define MAX_NUMNZ 9000000
....
typedef struct Polytope {
int rmatbeg[MAX_NUMROWS];
int rmatind[MAX_NUMNZ];
double rmatval[MAX_NUMNZ];
double rhs[MAX_NUMROWS];
char sense[MAX_NUMROWS];
double cosine[MAX_NUMROWS];
double norm[MAX_NUMROWS];
/* char *rowname[MAX_NUMROWS]; */
} a_polytope, aa_polytope;
....
and in main.h, I have:
....
extern struct Polytope a_polytope, aa_polytope ;
in main.c , if the external variable a_polytope is
used as a function's parameters such as :
status = CPXaddrows (env, lp, 0, num_rows, num_nonzero,
a_polytope.rhs, a_polytope.sense,a_polytope.rmatbeg,
a_polytope.rmatind, a_polytope.rmatval, NULL, NULL);
/* this is a CPLEX callable library function */
I will get "invalid use of undefined type `struct
Polytope'" error in compiling.
It was working OK when all codes were in sigle file without using
keyword "extern".
If I change main.h into:
....
extern struct Polytope a_polytope, aa_polytope ;
struct Polytope *pa_polytope, *paa_polytope ;
....
and also change main.c into
pa_polytope = &a_polytope ;
status = CPXaddrows (env, lp, 0,num_rows, num_nonzero,
pa_polytope->rhs,pa_polytope->sense,pa_polytope->rmatbeg,
pa_polytope->rmatind,pa_polytope->rmatval,
NULL, NULL);
I will get "dereferencing pointer to incomplete type"
four times for each pa_polytope->xxxx above.
Does anyone have a suggestion?
Thank you so much!
Now I encounter a problem about the global variables
and can not find a way to solve it.
All global variables and codes used to be in that single file, that
worked OK. But when I divdie that file into several ones, I
have many "invalid use of undefined type" errors.
The four files are main.c, main.h, readLP.h, and readLP.c.
In readLP.h
I have:
#define MAX_NUMROWS 181010
#define MAX_NUMCOLS 201
#define MAX_NUMNZ 9000000
....
typedef struct Polytope {
int rmatbeg[MAX_NUMROWS];
int rmatind[MAX_NUMNZ];
double rmatval[MAX_NUMNZ];
double rhs[MAX_NUMROWS];
char sense[MAX_NUMROWS];
double cosine[MAX_NUMROWS];
double norm[MAX_NUMROWS];
/* char *rowname[MAX_NUMROWS]; */
} a_polytope, aa_polytope;
....
and in main.h, I have:
....
extern struct Polytope a_polytope, aa_polytope ;
in main.c , if the external variable a_polytope is
used as a function's parameters such as :
status = CPXaddrows (env, lp, 0, num_rows, num_nonzero,
a_polytope.rhs, a_polytope.sense,a_polytope.rmatbeg,
a_polytope.rmatind, a_polytope.rmatval, NULL, NULL);
/* this is a CPLEX callable library function */
I will get "invalid use of undefined type `struct
Polytope'" error in compiling.
It was working OK when all codes were in sigle file without using
keyword "extern".
If I change main.h into:
....
extern struct Polytope a_polytope, aa_polytope ;
struct Polytope *pa_polytope, *paa_polytope ;
....
and also change main.c into
pa_polytope = &a_polytope ;
status = CPXaddrows (env, lp, 0,num_rows, num_nonzero,
pa_polytope->rhs,pa_polytope->sense,pa_polytope->rmatbeg,
pa_polytope->rmatind,pa_polytope->rmatval,
NULL, NULL);
I will get "dereferencing pointer to incomplete type"
four times for each pa_polytope->xxxx above.
Does anyone have a suggestion?
Thank you so much!