-
Odd Problem with Linking
Hi,
I have a program that includes an external file named
"atomgr.inc".
in my code I first tried including this way:
#include "atomgr.inc"
I compile it and get linking errors such as:
[LinkerError] Unresolved external '_seqnum' referenced from C:\PROGRAM FILES\BORLAND\CBUILDER3\PROJECTS\UNIQUITIZERCPP092 105\MAIN.OBJ.
Next, I moved the atomgr.inc file into my include directory and
changed the line in my code to
#include <atomgr.inc>
I tried compiling it and get the same linking errors. Does anyone know what could be causing this?
Thanks
James
-
Can you show us the contents of atomgr.inc?
-
Contents of atomgr.inc
Sure, here's the contents. There are other include files as well, but this holds most of the variables that are going unresolved:
*
* INTERNAL GRAPH REPRESENTATION OF A (HYDROGEN SUPPRESSED) ATOMIC STRUCTURE
*/
/*
* conversion note from Fortran to C:
* There is a great deal of dependency by the Fortran
* code on 1-based data arrays. Therefore, the C will
* make all data arrays 1 item longer, and use 1-based
* loops for them. We will handle character strings
* as zero-based, per C usage.
*
* Not the best solution, * but it will be a lot closer
* to the algorithms of the original authors.
*/
/*
* MAXIMUM # OF EXPLICIT ATOMS ALLOWED
*/
#define MAXATM 60
#define MAXDEG 6 /* MAX # OF EXPLICIT NEIGHBORS PER ATOM */
#define MAXBND (MAXATM*MAXDEG)/2 /* MAXIMUM # OF BONDS POSSIBLE */
/*
* NOTE: THIS IS GLOBAL data. It is maintained in fixed
* memory for all functions that use this include file
* there are no constant initializations for these
* variables and arrays (thank heaven)
*/
#ifdef MAIN_PROGRAM
int seqnum = 999; /* SEQUENCE NUMBER--THIS IS Nth CHEMICAL */
int natoms; /* NUMBER OF EXPLICIT ATOMS IN STRUCTURE */
int atom[MAXATM+1]; /* HOLDS CODE FOR THE TYPE OF EACH ATOM */
int charge[MAXATM+1]; /* MEASURES THE CHARGE ON EACH ATOM */
int netcha; /* NET CHARGE; SUM OF ALL ATOMIC CHARGES */
int naroma[MAXATM+1]; /* NUMBER OF AROMATIC BONDS TO THE ATOM */
int contrb[MAXATM+1]; /* RING CONTRIBUTION IFF AROMATIC ATOM */
int bcount[MAXATM+1]; /* WEIGHTED TOTAL OF EXPLICIT BONDS */
int hydros[MAXATM+1]; /* # OF IMPLICIT HYDROGENS ON EACH ATOM */
int nhydro; /* # OF IMPLICIT HYDROGENS IN STRUCTURE */
int degree[MAXATM+1]; /* # OF EXPLICIT NEIGHBORING ATOMS */
int bnext[MAXDEG+1][MAXATM+1]; /* POINTS TO THE NEIGHBORING ATOMS */
int btype[MAXDEG+1][MAXATM+1]; /* GIVES TYPE OF BOND TO NEIGHBOR */
int bnumb[MAXDEG+1][MAXATM+1]; /* SEQUENTIAL NUMBER OF THAT BOND */
int nbonds; /* TOTAL NUMBER OF BONDS */
int ncomps; /* NUMBER OF SEPARATE GRAPH COMPONENTS */
int aromat[MAXATM+1]; /* FALSE (0) IFF ATOM HAS NO AROMATIC BONDS */
int ehflag[MAXATM+1]; /* ATTACHED HYDROGENS ARE EXPLICIT */
char bconf[MAXBND+1]; /* Bond CONFormation: ' ',c,t,C,T,E,Z */
char conf[MAXATM+1]; /* atom CONFormation: above + R,S,A,Q,J */
#else
extern int seqnum; /* SEQUENCE NUMBER--THIS IS Nth CHEMICAL */
extern int natoms; /* NUMBER OF EXPLICIT ATOMS IN STRUCTURE */
extern int atom[MAXATM+1]; /* HOLDS CODE FOR THE TYPE OF EACH ATOM */
extern int charge[MAXATM+1]; /* MEASURES THE CHARGE ON EACH ATOM */
extern int netcha; /* NET CHARGE; SUM OF ALL ATOMIC CHARGES */
extern int naroma[MAXATM+1]; /* NUMBER OF AROMATIC BONDS TO THE ATOM */
extern int contrb[MAXATM+1]; /* RING CONTRIBUTION IFF AROMATIC ATOM */
extern int bcount[MAXATM+1]; /* WEIGHTED TOTAL OF EXPLICIT BONDS */
extern int hydros[MAXATM+1]; /* # OF IMPLICIT HYDROGENS ON EACH ATOM */
extern int nhydro; /* # OF IMPLICIT HYDROGENS IN STRUCTURE */
extern int degree[MAXATM+1]; /* # OF EXPLICIT NEIGHBORING ATOMS */
extern int bnext[MAXDEG+1][MAXATM+1]; /* POINTS TO THE NEIGHBORING ATOMS */
extern int btype[MAXDEG+1][MAXATM+1]; /* GIVES TYPE OF BOND TO NEIGHBOR */
extern int bnumb[MAXDEG+1][MAXATM+1]; /* SEQUENTIAL NUMBER OF THAT BOND */
extern int nbonds; /* TOTAL NUMBER OF BONDS */
extern int ncomps; /* NUMBER OF SEPARATE GRAPH COMPONENTS */
extern int aromat[MAXATM+1]; /* FALSE (0) IFF ATOM HAS NO AROMATIC BONDS */
extern int ehflag[MAXATM+1]; /* ATTACHED HYDROGENS ARE EXPLICIT */
extern char bconf[MAXBND+1]; /* Bond CONFormation: ' ',c,t,C,T,E,Z */
extern char conf[MAXATM+1]; /* atom CONFormation: above + R,S,A,Q,J */
#endif
-
I'm pretty sure that it's something to do with use of the extern keyword, but seeing as how I have a bad habit of screwing up the proper usage of it, I'm going to refrain from attempting to answer. Someone else should be able to figure it out.
-
Thanks for taking a look at it. I'm new to programming and will look into the
extern keyword. This is an old program that was originally written in fortran, ported to
C and then C++ so there are many bugs.
-
That header is only declaring the names of the variables (to make them available to all source files including the header). They must be defined in one and only one source file, otherwise you'll get linker errors.
This header seems to be prepared for this, so define the macro MAIN_PROGRAM in one and only one of your source files:
Code:
//In one source file
#define MAIN_PROGRAM
//In every source file
#include "atomgr.inc"
-
Thanks, it works!
I defines the macro MAIN_PROGRAM in my main.cpp page and it solved the problem