LNK2019: unresolved external symbol 'symbol' referenced in function 'function'; fatal

This is a discussion on LNK2019: unresolved external symbol 'symbol' referenced in function 'function'; fatal within the C++ Programming forums, part of the General Programming Boards category; Hi I made a simple C++ program and I'm getting errors and I don't know what I'm doing wrong. I'm ...

  1. #1
    Registered User
    Join Date
    Feb 2011
    Posts
    6

    LNK2019: unresolved external symbol 'symbol' referenced in function 'function'; fatal

    Hi I made a simple C++ program and I'm getting errors and I don't know what I'm doing wrong. I'm new to C++ syntax so I can't figure out what mistake I made that is causing the stated linker errors. The generated error complains that my Test1::getNmNeighborhoodEntry() function does not exist so linking can't happen. I must be missing something obvious a more seasoned programmer can see. Here is sample code that generates this error:

    ITest.h
    Code:
    #ifndef ITest_H
    #define ITest_H
    
    //#[ ignore
    #ifdef _MSC_VER
    // disable Microsoft compiler warning (debug information truncated)
    #pragma warning(disable: 4786)
    #endif
    //#]
    
    //## auto_generated
    #include <string>
    //## auto_generated
    #include <algorithm>
    //## auto_generated
    //## link itsNmNeighborhoodEntry
    class NmNeighborhoodEntry;
    //## class ITest
    class ITest {
    //#[ ignore
    
        ////    Constructors and destructors    ////
    
    public :
    
        //## auto_generated
        virtual ~ITest();
    
        ////    Relations and components    ////
    
    protected :
    
        NmNeighborhoodEntry* itsNmNeighborhoodEntry;        //## link itsNmNeighborhoodEntry
    };
    
    #endif
    ITest.cpp

    Code:
    //## auto_generated
    #include "ITest.h"
    //## link itsNmNeighborhoodEntry
    #include "NmNeighborhoodEntry.h"
    
    //## class ITest
    ITest::~ITest() {
    }
    Test1.h

    Code:
    #ifndef Test1_H
    #define Test1_H
    
    //#[ ignore
    #ifdef _MSC_VER
    // disable Microsoft compiler warning (debug information truncated)
    #pragma warning(disable: 4786)
    #endif
    //#]
    
    //## auto_generated
    #include <string>
    //## auto_generated
    #include <algorithm>
    //## class Test1
    #include "ITest.h"
    //## auto_generated
    class NmNeighborhoodEntry;
    
    //## class Test1
    class Test1 : public ITest {
    //#[ ignore
    
        // Default Constructor is Private
        public:
           Test1();
    
    
        // Default Copy Constructor is Private
        private:
           Test1(const Test1& self);
    
    
        // Default Assignment Operator is Private
        private:
           Test1& operator=(const Test1& aTest1);
    //#]
    
        ////    Constructors and destructors    ////
    
    public :
    
        //## auto_generated
        ~Test1();
    
        NmNeighborhoodEntry* getNmNeighborhoodEntry();
    };
    
    #endif
    Test1.cpp

    Code:
    //## auto_generated
    #include "Test1.h"
    //## auto_generated
    #include "NmNeighborhoodEntry.h"
    
    NmNeighborhoodEntry* itsNmNeighborhoodEntry;
    
    //## class Test1
    Test1::~Test1() {
    }
    
    Test1::Test1() {
    }
    
    
    NmNeighborhoodEntry* getNmNeighborhoodEntry() { 
        //return itsNmNeighborhoodEntry;
        return NULL;
    }
    NmNeighborhoodEntry.h

    Code:
    #ifndef NmNeighborhoodEntry_H
    #define NmNeighborhoodEntry_H
    
    //#[ ignore
    #ifdef _MSC_VER
    // disable Microsoft compiler warning (debug information truncated)
    #pragma warning(disable: 4786)
    #endif
    //#]
    
    //## auto_generated
    #include <string>
    //## auto_generated
    #include <algorithm>
    
    //## class NmNeighborhoodEntry
    
    class NmNeighborhoodEntry {
    //#[ ignore
    
        // Default Constructor is Private
        private:
           NmNeighborhoodEntry();
    
    
        // Default Copy Constructor is Private
        private:
           NmNeighborhoodEntry(const NmNeighborhoodEntry& self);
    
    
        // Default Assignment Operator is Private
        private:
           NmNeighborhoodEntry& operator=(const NmNeighborhoodEntry& aNmNeighborhoodEntry);
    //#]
    
        ////    Constructors and destructors    ////
    
    public :
    
        //## auto_generated
        ~NmNeighborhoodEntry();
    
        bool myIsPending;       //## attribute myIsPending
    
        unsigned short index;       //## attribute myNodeIndex
    };
    
    #endif
    [

    NmNeighborhoodEntry.cpp

    Code:
    //## auto_generated
    #include "NmNeighborhoodEntry.h"
    
    //## class NmNeighborhoodEntry
    NmNeighborhoodEntry::~NmNeighborhoodEntry() {
    }
    driver.cpp

    Code:
    //#include "ITest.h"
    #include "Test1.h"
    //#include "Test2.h"
    #include "NmNeighborhoodEntry.h"
    
    Test1 *test1;
    //Test2 *test2;
    NmNeighborhoodEntry* myNmNeighborhoodEntry;
    
    void main() {
        test1 = new Test1;
        //test2 = new Test2;
    
        //test1->itsNmNeighborhoodEntry = NULL;
        myNmNeighborhoodEntry = test1->getNmNeighborhoodEntry();
    
    }

  2. #2
    Just a pushpin. bernt's Avatar
    Join Date
    May 2009
    Posts
    426
    In test1.cpp, you need to specify the scope of the get function, just like you did with the constructors:
    Code:
    NmNeighborhoodEntry* Test1::getNmNeighborhoodEntry() {
        //return itsNmNeighborhoodEntry;
        return NULL;
    }
    Consider this post signed

  3. #3
    Registered User
    Join Date
    Feb 2011
    Posts
    6
    Quote Originally Posted by bernt View Post
    In test1.cpp, you need to specify the scope of the get function, just like you did with the constructors:
    Code:
    NmNeighborhoodEntry* Test1::getNmNeighborhoodEntry() {
        //return itsNmNeighborhoodEntry;
        return NULL;
    }
    Thanks!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LNK2019 unresolved external symbol
    By Freddy92 in forum C++ Programming
    Replies: 1
    Last Post: 05-03-2011, 06:00 AM
  2. Help with: error LNK2019: unresolved external symbol
    By darren78 in forum C++ Programming
    Replies: 2
    Last Post: 06-16-2010, 06:26 AM
  3. LNK2019 unresolved external symbol
    By lerckeman in forum C++ Programming
    Replies: 2
    Last Post: 12-16-2006, 01:34 AM
  4. error LNK2019: unresolved external symbol
    By Opel_Corsa in forum C++ Programming
    Replies: 3
    Last Post: 11-16-2006, 11:12 AM
  5. LNK2019: unresolved external symbol
    By mhandlon in forum Windows Programming
    Replies: 3
    Last Post: 01-19-2006, 11:55 AM

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