extern defined functions

This is a discussion on extern defined functions within the C Programming forums, part of the General Programming Boards category; I am trying to include externally defined functions in my main function but when I try to compile using: Code: ...

  1. #1
    Registered User
    Join Date
    Mar 2010
    Posts
    61

    extern defined functions

    I am trying to include externally defined functions in my main function but when I try to compile using:

    Code:
    cc assemble.c pass1.o pass2.o getsource.o -o assemble
    I get the following errors:

    Code:
    assemble.c: In function `main':
    assemble.c:57: warning: passing arg 1 of `getsource' from incompatible pointer type
    pass1.o(.text+0x178): In function `pass1':
    /home/37/n00449937/cop3601/pass1.c:63: undefined reference to `breakup'
    pass1.o(.text+0x24f):/home/37/n00449937/cop3601/pass1.c:78: undefined reference to `insert'
    pass1.o(.text+0x2ec):/home/37/n00449937/cop3601/pass1.c:84: undefined reference to `breakup'
    pass1.o(.text+0x370):/home/37/n00449937/cop3601/pass1.c:93: undefined reference to `findfirst'
    pass1.o(.text+0x3e6):/home/37/n00449937/cop3601/pass1.c:102: undefined reference to `insert'
    pass1.o(.text+0x41b):/home/37/n00449937/cop3601/pass1.c:111: undefined reference to `findfirst'
    pass1.o(.text+0x4e6):/home/37/n00449937/cop3601/pass1.c:129: undefined reference to `storageincr'
    pass1.o(.text+0x539):/home/37/n00449937/cop3601/pass1.c:141: undefined reference to `storageincr'
    pass1.o(.text+0x58d):/home/37/n00449937/cop3601/pass1.c:153: undefined reference to `opcodeincr'
    pass1.o(.text+0x655):/home/37/n00449937/cop3601/pass1.c:171: undefined reference to `breakup'
    pass1.o(.text+0x68f):/home/37/n00449937/cop3601/pass1.c:176: undefined reference to `findfirst'
    pass1.o(.text+0x705):/home/37/n00449937/cop3601/pass1.c:185: undefined reference to `insert'
    pass1.o(.text+0x74f):/home/37/n00449937/cop3601/pass1.c:196: undefined reference to `findfirst'
    pass2.o(.text+0x178): In function `pass2':
    /home/37/n00449937/cop3601/pass2.c:68: undefined reference to `breakup'
    pass2.o(.text+0x24c):/home/37/n00449937/cop3601/pass2.c:82: undefined reference to `breakup'
    pass2.o(.text+0x2b7):/home/37/n00449937/cop3601/pass2.c:92: undefined reference to `findfirst'
    pass2.o(.text+0x37f):/home/37/n00449937/cop3601/pass2.c:110: undefined reference to `storageincr'
    pass2.o(.text+0x3b1):/home/37/n00449937/cop3601/pass2.c:123: undefined reference to `storageincr'
    pass2.o(.text+0x3d7):/home/37/n00449937/cop3601/pass2.c:133: undefined reference to `opcodeincr'
    pass2.o(.text+0x4b5):/home/37/n00449937/cop3601/pass2.c:171: undefined reference to `breakup'
    getsource.o(.text+0xb1): In function `getsource':
    /home/37/n00449937/cop3601/getsource.c:24: undefined reference to `hprintf'
    collect2: ld returned 1 exit status
    Here is the code in my assemble.c program that is trying to include the externally defined functions:

    Code:
    /* Pre-Processor Directives */
    #include "cop3601.h"
    #define SYMBSIZE 10
    #define SYMBLIMIT 200
    #define SOURCELIMIT 500
    
    typedef struct
    {
       char symbol[SYMBSIZE];
       int value;
       int casenmbr;
       int otherinfo;
    } tabletype;
    
    typedef struct
    {
       char *lbl;
       char *opc;
       char *opr1;
       char *opr2;
       int *ni;
       int *xbpe;
    } comptype;
    
    extern int getsource();
    extern int pass1();
    extern int pass2();
    
    char sourcelist[SOURCELIMIT][81];
    int sourcecnt;
    int errors[SOURCELIMIT];
    tabletype symbtab[SYMBLIMIT];
    int symbtabsize;
    tabletype codetable[]=
    {
       #include "codetable"
    };
    int codetabsize = sizeof(codetable)/sizeof(tabletype);
    char objline[81];
    
    /* Prototypes */
    int getsource(char *filename[]);
    int pass1(void);
    int pass2(void);
    
    int main(int argc, char *argv[])
    { }

  2. #2
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Somebody has to write those functions that are missing. If it wasn't supposed to be somebody else, I guess that somebody is you.

  3. #3
    Registered User
    Join Date
    Mar 2010
    Posts
    61
    I have the functions written, and they're in the same directory

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Then compile them, and link them with everything else.

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    61
    that's what I'm trying to do but when I compile it still says it has an undefined reference

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You didn't put any of the functions in assemble.c. What file did you put them in? You need that file too.

  7. #7
    Registered User
    Join Date
    Mar 2010
    Posts
    61
    Ok, I figured out a way to compile it that seems to resolve the issue, thanks for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Extern functions?
    By Petike in forum C++ Programming
    Replies: 8
    Last Post: 08-06-2008, 12:33 PM
  2. Visual Studio C Help
    By Paul22000 in forum C Programming
    Replies: 26
    Last Post: 05-01-2008, 09:13 AM
  3. Extern functions calls
    By mariano_donati in forum C Programming
    Replies: 13
    Last Post: 02-14-2008, 07:21 AM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 05:58 PM
  5. Header files
    By borland_man in forum C++ Programming
    Replies: 14
    Last Post: 02-22-2002, 03:30 AM

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