Odd Problem with Linking

This is a discussion on Odd Problem with Linking within the C++ Programming forums, part of the General Programming Boards category; Hi, I have a program that includes an external file named "atomgr.inc". in my code I first tried including this ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    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

  2. #2
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Can you show us the contents of atomgr.inc?
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    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
    Last edited by jamez05; 09-21-2005 at 01:18 PM. Reason: Additional info

  4. #4
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    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.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    80
    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.

  6. #6
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    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"
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    80

    Wink Thanks, it works!

    I defines the macro MAIN_PROGRAM in my main.cpp page and it solved the problem

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with linking files
    By slippy in forum C Programming
    Replies: 2
    Last Post: 11-23-2007, 10:35 PM
  2. Odd Linux Problem
    By Draco in forum Tech Board
    Replies: 4
    Last Post: 05-21-2006, 06:55 PM
  3. Linking problem
    By Magos in forum C++ Programming
    Replies: 4
    Last Post: 09-03-2004, 03:21 PM
  4. Long file linking problem
    By hypertension in forum C Programming
    Replies: 3
    Last Post: 10-15-2002, 09:55 PM
  5. Linking problem...
    By BrianK in forum C++ Programming
    Replies: 2
    Last Post: 10-08-2002, 04:13 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21