Link error: Symbols not found (with code)

Discussion in 'Mac Programming' started by farmerdoug, Sep 24, 2011.

  1. farmerdoug macrumors 6502a

    Joined:
    Sep 16, 2008
    #1
    Mid_Vol is not found.
    Code:
    void LEVERED (char *** special, char * firstdate, char * lastdate, int no_days);
    void HI_ER (char *** special,char * firstdate,char * lastdate, int no_days );
    void Lo_ER (char *** special,char * firstdate,char * lastdate, int no_days );
    void HI_Vol (char *** special,char * firstdate,char * lastdate, int no_days );
    void Lo_Vol (char *** special,char * firstdate,char * lastdate, int no_days );
    void Mid_Vol (char *** special,char * firstdate,char * lastdate, int no_days );
    void Mid_ER (char *** special,char * firstdate,char * lastdate, int no_days );
    int main (int argc, const char * argv[]) {
    ...
        LEVERED (special, firstdate, lastdate, testperiod);   
        HI_ER(special, firstdate, lastdate, testperiod);
        Lo_ER(special, firstdate, lastdate, testperiod);
    
        HI_Vol(special, firstdate, lastdate, testperiod);
        Lo_Vol(special, firstdate, lastdate, testperiod);
       
        Mid_Vol(special, firstdate, lastdate, testperiod);
        Mid_ER(special, firstdate, lastdate, testperiod);
    }
    return (0)
    
    
    void Mid_Vol (char *** special, char * firstdate, char * lastdate, int no_days) 
      {      
    return;
    }
    
     
  2. lee1210 macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    Is return (0) after the } ending main? And is it lacking a semicolon? It looks to me like there is a line that reads:
    return (0) void Mid_Vol...

    Which is not so good.

    -Lee
     
  3. chown33 macrumors 604

    Joined:
    Aug 9, 2009
  4. farmerdoug thread starter macrumors 6502a

    Joined:
    Sep 16, 2008
    #4
    Lee: It was just a sloppy job of cutting and pasting.
    Chown

    Build trades of project trades with configuration Release

    Ld build/trades.build/Release/trades.build/Objects-normal/x86_64/trades normal x86_64
    cd /Users/doug/tulip/trades
    setenv MACOSX_DEPLOYMENT_TARGET 10.6
    /Developer/usr/bin/gcc-4.2 -arch x86_64 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/doug/tulip/trades/build/Release -F/Users/doug/tulip/trades/build/Release -filelist /Users/doug/tulip/trades/build/trades.build/Release/trades.build/Objects-normal/x86_64/trades.LinkFileList -mmacosx-version-min=10.6 -o /Users/doug/tulip/trades/build/trades.build/Release/trades.build/Objects-normal/x86_64/trades

    Undefined symbols:
    "_Mid_ER", referenced from:
    _main in main.o
    "_Mid_Vol", referenced from:
    _main in main.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status

    Ld build/trades.build/Release/trades.build/Objects-normal/i386/trades normal i386
    cd /Users/doug/tulip/trades
    setenv MACOSX_DEPLOYMENT_TARGET 10.6
    /Developer/usr/bin/gcc-4.2 -arch i386 -isysroot /Developer/SDKs/MacOSX10.6.sdk -L/Users/doug/tulip/trades/build/Release -F/Users/doug/tulip/trades/build/Release -filelist /Users/doug/tulip/trades/build/trades.build/Release/trades.build/Objects-normal/i386/trades.LinkFileList -mmacosx-version-min=10.6 -o /Users/doug/tulip/trades/build/trades.build/Release/trades.build/Objects-normal/i386/trades

    Undefined symbols:
    "_Mid_ER", referenced from:
    _main in main.o
    "_Mid_Vol", referenced from:
    _main in main.o
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
     
  5. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #5
    Without seeing the actual code of main.c here's my guess.

    There may be some kind of syntax error before the definition of Mid_ER() or Mid_Vol() that's causing the function definition to not compile as an actual function. For example, a missing } might do this, but it might also cause an error about nested functions not being permitted. Or it might only be a warning about nested functions, which you're ignoring as seemingly insignificant.

    There may be some macro definition that comes after these function declarations:
    Code:
    void Mid_Vol (char *** special,char * firstdate,char * lastdate, int no_days );
    void Mid_ER (char *** special,char * firstdate,char * lastdate, int no_days );
    
    and after main(), which seems to use the declarations, but before the functions are actually defined. The macro would define Mid_Vol and Mid_Er as something else, so the resulting actual name of the function isn't as declared.

    Both possibilities depend on the actual file and its actual structural organization (i.e. the actual arrangement of text in the file). Therefor, a reduced version of main.c is pretty unlikely to show the cause of the problem.

    I assume main.o is being compiled as C code from main.c, and not as C++ or Objective-C++. Because compiling as C++ might also lead to a symbol mismatch.


    If you're looking for something to try, cut and paste the complete definition of one of the functions so it comes before main(). This would take it out of the problematic lexical scope, if there is one.

    Doing so may cause another error, or it may cause the error to disappear. If it disappears, then the problem is something that comes before wherever it was that you cut the original function definition from. So use basic binary search and cut/paste to isolate what range of lines causes the problem.
     
  6. farmerdoug thread starter macrumors 6502a

    Joined:
    Sep 16, 2008
    #6
    Code attached.
    Same error
     

    Attached Files:

  7. chown33, Sep 24, 2011
    Last edited: Sep 24, 2011

    chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #7
    Your posted code led me to believe the missing functions were defined in main.c. This isn't true. They are defined in separate files (compilation units, in C parlance).

    You need to double-check the case of the unresolved functions, in their source files and in main.c's declarations.

    This one is definitely wrong (from "MID_ER.c"):
    Code:
    void MID_ER (char *** special, char * firstdate, char * lastdate, int no_days) 
    
    C is case-sensitive, even when you're not.


    Another possibility is you've added a source file to the project, but have neglected to add it to the build target.

    EDIT
    Nope, even simpler than that: neither MID_Vol.c nor MID_ER.c were even added to the project.

    Add both files, fix the spelling of MID_ER, and it compiles fine.

    My invoice is in the mail.
     
  8. farmerdoug thread starter macrumors 6502a

    Joined:
    Sep 16, 2008
    #8
    Of Course! And I can't tell you how many times I checked the spelling.
    But there's more. I fix the case errors and the abbreviated code I sent compiled and linked. However, fixing the case errors in the full code didn't help; then I managed to make things worse. I finally got it right by starting over with a new project which compiled and linked without code changes.

    Thanks.
     

Share This Page