Linking error LNK2019: unresolved external symbol

This is a discussion on Linking error LNK2019: unresolved external symbol within the C++ Programming forums, part of the General Programming Boards category; Hi, I have a miniproject in MVS2005 wich keeps bugging me with linking errors. I've read the documentation provided by ...

  1. #1
    Registered User
    Join Date
    Jul 2008
    Posts
    14

    Unhappy Linking error LNK2019: unresolved external symbol

    Hi,

    I have a miniproject in MVS2005 wich keeps bugging me with linking errors. I've read the documentation provided by MSV related to this error, and nothing seems to solve my problem.
    So I came to you again for a helping hand.

    ListaGenerica.h:
    Code:
    #include <iostream>
    using namespace std;
    
    template <class DataType>
    struct NodeList
    {
    	DataType m_sData;
    	NodeList* nxt;
    	NodeList* prv;
    };
    
    template <class DataType>
    class DLnkList
    {
    protected:
    	NodeList<DataType>* pHead;
    public:
    	DLnkList()
    	{
    		pHead = new NodeList<DataType>;
    		pHead = NULL;
    	}
    	~DLnkList()
    	{
    		while( pHead != NULL )    
    		{
    			NodeList<DataType>* pAux = pHead; 
    			pHead = pAux->nxt;   
    			delete pAux;  
    			cout<<"destr";
    		}
    	}
    	void AddNode(DataType Data);
    	void ShowList();
    };
    The ListaGenerica.cpp:
    Code:
    #include "ListaGenerica.h"
    #include <string>
    #include <iostream>
    using namespace std;
    
    template <class DataType>
    void  DLnkList<DataType>::AddNode(DataType Data)
    {
    	NodeList<DataType>* pNewNode = new NodeList<DataType>;
    	pNewNode->nxt = pHead;
    	pHead = pNewNode;
    	pNewNode->m_sData = Data;
    }
    
    template <class DataType>
    void DLnkList<DataType>::ShowList()
    {
    	NodeList<DataType>* pAux;
    	pAux = pHead; 
    	while( pAux != NULL )         
    	{
    		cout << endl << pAux->m_sData;
    		pAux = pAux->nxt;
    	}
    }
    And Main.cpp:
    Code:
    #include "ListaGenerica.h"
    #include <string>
    #include <iostream>
    using namespace std;
    
    int main(void)
    {
    	DLnkList<int>* ol = new DLnkList<int>;
    	ol->AddNode(5555);
    	ol->ShowList();
    	delete ol;
    }
    and here are the errors:

    Code:
    1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall DLnkList<int>::ShowList(void)"
     (?ShowList@?$DLnkList@H@@QAEXXZ) referenced in function _main
    1>main.obj : error LNK2019: unresolved external symbol "public: void __thiscall DLnkList<int>::AddNode(int)"
     (?AddNode@?$DLnkList@H@@QAEXH@Z) referenced in function _main
    When i copy the function definitions in main.cpp, te project builds. Why doesn't the builder see the ListaGenerica.cpp?
    Any hints?
    Tank you.
    Last edited by tzakieta; 09-19-2008 at 08:06 AM.

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    890
    Unless your compiler supports "export", you'll have to put the AddNode and ShowList code in the header file.

  3. #3
    Registered User
    Join Date
    Jul 2008
    Posts
    14
    Curious, because I've done the exact positioning of files in numerous projects and it worked.

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    That's the fun part about templates -- the template definition itself must be visible when the function is instantiated (unless and until the export keyword is supported).

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  3. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  4. Stupid compiler errors
    By ChrisEacrett in forum C++ Programming
    Replies: 9
    Last Post: 11-30-2003, 05:44 PM
  5. debug to release modes
    By DavidP in forum Game Programming
    Replies: 5
    Last Post: 03-20-2003, 03:01 PM

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