[RESOLVED] New 'LNK2019: unresolved external' Error
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Thread: [RESOLVED] New 'LNK2019: unresolved external' Error

  1. #1
    Join Date
    Jan 2009
    Posts
    5

    [RESOLVED] New 'LNK2019: unresolved external' Error

    I have an existing VS C++ console application that I have been updating over the past couple of days. This morning I added a new function to one of the classes, and suddenly started getting this error when building:

    error LNK2019: unresolved external symbol "public: char * __thiscall mFormatDef::ByteFormat(__int64,int,enum siCalcFormat,enum siDisplayFormat,int)" (?ByteFormat@mFormatDef@@QAEPAD_JHW4siCalcFormat@@W4siDisplayFormat@@H@Z) referenced in function "void __cdecl ShowStuff(void)" (?ShowStuff@@YAXXZ)

    I have verified the definition, all variables, etc, and still can't figure out where the problem is coming from. I have changed the name of the function, variable types and count, same issue. I jumped over to Borland C++ Builder for testing, it compiles the code fine. I created a new VS C++ project including the class and making random calls to the function, compiles and runs fine.

    I have 'cleaned' the project, deleted all non-code files, rebuilt all, same linker error. I am out of ideas. Does anyone have any thoughts on anything I may have missed? Anything to check? Anything at all???

    Any help will be appreciated! Thanks,
    Jim

  2. #2
    Join Date
    Apr 1999
    Posts
    27,424

    Re: New 'LNK2019: unresolved external' Error

    Quote Originally Posted by jimmiller96 View Post
    I have 'cleaned' the project, deleted all non-code files, rebuilt all, same linker error.
    We don't have your project, so we can't tell you what you're doing wrong.
    Does anyone have any thoughts on anything I may have missed?
    The only thing to tell you as that you're doing something wrong, or your project is messed up.

    Just start over and create a new project. If it still is occurring, then there is something else that you are not aware of that you're not doing. The linker doesn't lie.

    Regards,

    Paul McKenzie

  3. #3
    Join Date
    Jan 2009
    Posts
    5

    Re: New 'LNK2019: unresolved external' Error

    Quote Originally Posted by Paul McKenzie View Post
    We don't have your project, so we can't tell you what you're doing wrong.
    I have stripped down the components to the bare minimum, the following will compile, but will still prevent a successful link.

    Definition:
    Code:
    enum siDisplayFormat2 {siNOLETTER2 = 0, siMB2, siMIB2}; 
    enum siCalcFormat2 {si10002, si10242}; 
    
    class mFmtDef
    {
      public:
    	char*	ByteFormat(__int64 Number, int iDigits, siCalcFormat2 siCFmt = si10242, siDisplayFormat2 siDFmt = siMB2, bool bIncLetters = false);
    };
    
    char* mFmtDef::ByteFormat(__int64 Number, int iDigits, siCalcFormat siCFmt, siDisplayFormat siDFmt, bool bIncLetters)
    {
    	char *sz = 0;
    	return sz;
    }
    Usage:

    Code:
    mFmtDef mFmt;
    mFmt.ByteFormat(1000000, 2, si10242, siMB2, true);
    ShowStuff function
    Code:
    void ShowStuff(void)
    {
        mFormatDef mFmt;
        __int64 i64Size = 2 ^ 30;  //1 TiB
    
        //Print out UNformatted size of file
        printf("Bytes= %I64d \n", i64Size);
    
        //Print out formatted size of file
        printf("Total Size= %s \n", mFmt.ByteFormat(i64Size, 2, si10242, siMB2, true));
    
    }
    (As I mentioned at the beginning, this class compiles and links just fine in Borland C++ Builder. I don't receive any warnings with with compiler, but VS2008 complains during the link. Doubly strange!)

    I initially thought the enums were messing things up, but switching everything to int and removing the enums doesn't improve the situation. I have other member functions in this class which compile and link without error. I also created a new VS project, but no improvement.

    What am I doing wrong here? Hopefully it's just some very stupid mistake, but I am totally stumped!

    Thanks for your time.
    Jim
    Last edited by jimmiller96; January 16th, 2009 at 01:01 PM. Reason: additional code

  4. #4
    Join Date
    Mar 2002
    Location
    NY, USA
    Posts
    12,097

    Re: New 'LNK2019: unresolved external' Error

    Quote Originally Posted by jimmiller96 View Post
    What am I doing wrong here? Hopefully it's just some very stupid mistake, but I am totally stumped!
    You are NOT using code tags, which renders your post too difficult to bother reading.

    If you EDIT your post (not make another post) that is properly tagged and formatted) I am confident that someone willl spot the problem.
    TheCPUWizard is a registered trademark, all rights reserved. (If this post was helpful, please RATE it!)
    2008, 2009
    In theory, there is no difference between theory and paractice; in practice there is.

    * Join the fight, refuse to respond to posts that contain code outside of [code] ... [/code] tags. See here for instructions
    * How NOT to post a question here
    * Of course you read this carefully before you posted
    * Need homework help? Read this first

  5. #5
    Join Date
    Jan 2002
    Location
    Houston, TX
    Posts
    1,421

    Re: New 'LNK2019: unresolved external' Error

    From what I understand of your post, you're trying to call a class member function
    Code:
    public: char * __thiscall mFormatDef::ByteFormat(__int64,int,enum siCalcFormat,enum siDisplayFormat,int)
    from a non-class function
    Code:
    void __cdecl ShowStuff(void)
    If you post the code contained in the ShowStuff function, it may help us see what's going wrong, but generally you can not directly call a class member function from a non-class member function (unless the class member function is static).

    Hope that helps.
    Be sure to rate those who help!
    -------------------------------------------------------------
    Karl - WK5M
    PP-ASEL-IA (N43CS)
    PGP Key: 0xDB02E193
    PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193

  6. #6
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: New 'LNK2019: unresolved external' Error

    Um, are siDisplayFormat and siDisplayFormat2 different types?

  7. #7
    Join Date
    Jan 2009
    Posts
    5

    Re: New 'LNK2019: unresolved external' Error

    Yes, same types, just different revisions from many different attempts. My latest rev looks like this:

    Code:
    char* mFormatDef::ByteFormat(__int64 Number, int iDigits, int  siCFmt, int  siDFmt, bool bIncLetters)
    {
    }
    and calling it with

    Code:
        printf("Total Size= %s \n", mFmt.ByteFormat(i64Size, 2, 1, 0, true));
    Same problem whether using enums or ints.

  8. #8
    Join Date
    Jan 2009
    Posts
    5

    Unhappy Re: New 'LNK2019: unresolved external' Error

    Well, it's been a few days of trying everything under the sun, and still no success. Here's the latest:

    - I create a new blank VS project and use the same class code: Success
    - I include and utilize the class in a new Borland project: Success
    - I re-create my original project, include all the same files: Failure

    I can't figure out why I am getting a link error with this one project. It almost seems like something from one of the source files is causing the problem, but the problem started in this project once I created the new class function. And it links successfully in other projects, and in other (and the same) compilers. The problem seems illogical, but I can't figure what is going here... I am totally stuck!

    Any more thoughts? I am willing to try anything!!!

    Thanks

  9. #9
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Fairfax, VA
    Posts
    10,888

    Re: New 'LNK2019: unresolved external' Error

    Perhaps you have an old declaration for the function lying around, which differs slightly from the actual definition. Check your header files. If the declaration is close enough to be convertible from how you use it but doesn't match the definition, this sort of thing could happen.

    I would do a "Search in entire solution" for ByteFormat. Barring that turning up anything, I'd right-click on *any* #include of the header in question and say "open this file"-----just to make sure you really are including the revision of that header you *think* you're including.

  10. #10
    Join Date
    Jan 2009
    Posts
    5

    Re: New 'LNK2019: unresolved external' Error

    Resolved, Finally!!!!

    As expected, it was something quite stupid. I have an old header file from DOS days that declared unknown types, including bool. This header file was being included from one of the source files, and redefined the parameter of type bool to int, which prevented the linker from properly identifying the member function.

    Thanks so much for all the suggestions, they kept me sane when I felt I was starting to lose it. Hopefully I will be able to prevent someone else from wasting a week of their life as well.

    Thanks again!
    Jim

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center