title: Error LNK2019 and Fatal error LNK1120: 2 unresolved externals
body: <p>I know my question and its answer exist anywhere on site but, I have more than it.</p>
  
  <p>I have zip library and use it in another C++ project.</p>
  
  <p>Zip library:
      <strong>czip.h</strong></p>
  
  <pre><code>#ifndef _CZIP_H_
  #define _CZIP_H_
  
  #include &lt;fcntl.h&gt;
  #include &lt;io.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;windows.h&gt;
  #include &lt;sys\stat.h&gt;
  
  #include &lt;stdio.h&gt;
  
  
  #ifndef DLL_INTERNAL
  #define DLL_INTERNAL __declspec( dllimport )
  #endif 
  
  class DLL_INTERNAL CZipException
  {
  public:
  CZipException( const char*fm, ... );
  const char* GetString() { return m_sMessage; }
  protected:
  char m_sMessage[ 128 ];
  };
  
  
  // pure virtual
  class DLL_INTERNAL CMamaZip
  {
  public:
  CMamaZip( const char *sSourceFileName );
  void SwapSize( const char *sTargetFileName );
  protected:
  virtual int HardWork( int inFile, int outFile ) = 0;
  
  char m_sSourceFileName[ MAX_PATH ];
  char *m_sOperation;
  };
  
  
  class DLL_INTERNAL CZip : public CMamaZip
  {
   public:
  CZip( const char *sSourceFileName );
   protected:
  virtual int HardWork( int inFile, int outFile );
  };
  
  
  class DLL_INTERNAL CUnzip : public CMamaZip
  {
   public:
  CUnzip( const char *sSourceFileName );
   protected:
  virtual int HardWork( int inFile, int outFile );
  };
  
  #endif // _CZIP_H_ 
  </code></pre>
  
  <p><strong>czip.cpp:</strong></p>
  
  <pre><code>#define DLL_INTERNAL __declspec( dllexport )
  #include "czip.h"
  #include "tailor.h"
  
  
  // global variables instancied in gzip 
  extern "C" {
  
  extern int dozip( int, int);
  extern int dounzip( int, int );
  extern long time_stamp;
  extern char ifname[MAX_PATH_LEN]; 
  extern int save_orig_name;
  
  extern int ifd;
  extern int ofd;
  
  } 
  
  int inFile, outFile;
  
  // this function is called by gzip when there is an error
  // instead of doing an exit( .. )
  extern "C" void do_exit_dll(int exitcode)
  {
  close( inFile );
  close( outFile );
  throw( CZipException( "problem with zipping/unzipping operation : %d", exitcode ) );    
  }  
  
  
  
  CZipException::CZipException( const char* fm, ... )
  {
  char *p = m_sMessage;
  va_list args;
  va_start( args, fm );
  p += vsprintf( p, fm, args);
  va_end( args );
  }
  
  
  int WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
  {
  return 1;
  } 
  
  
  
  CMamaZip::CMamaZip( const char *sUnzippedFileName )
  {
  strcpy( m_sSourceFileName, sUnzippedFileName );
  }
  
  
  // throw CZipException
  void CMamaZip::SwapSize( const char *sTargetFileName )
  {
  
  if (strcmp(m_sSourceFileName,sTargetFileName)==0)
      throw ( CZipException( "target name must be different than source name" ) );
  
  // try to open in unzipped file
  if ( ( inFile = open( m_sSourceFileName, _O_BINARY | _O_RDONLY ) ) == -1 )
      throw ( CZipException( "unable to open source file" ) );
  
  if ( ( outFile = open( sTargetFileName, _O_BINARY | _O_RDWR | _O_CREAT | _O_EXCL , _S_IREAD | _S_IWRITE  ) ) == -1 )
  {
      close(inFile);
      throw ( CZipException( "unable to create target file" ) );
  }
  
  ifd=inFile; ofd=outFile;
  int ret = HardWork( inFile, outFile );
  
  close( inFile );
  close( outFile );
  
  if (ret != 0)
      throw( CZipException( "problem while %s file", m_sOperation ) );
    }
  
  
   CZip::CZip( const char* sSourceFileName )
  : CMamaZip( sSourceFileName ) 
  
   { 
  m_sOperation = "zipping";   
  strcpy( ifname, m_sSourceFileName );
  save_orig_name = 1;
   }
  
  
   CUnzip::CUnzip( const char* sSourceFileName )
  : CMamaZip( sSourceFileName ) 
  
   { 
  m_sOperation = "unzipping";     
   }
  
   int CUnzip::HardWork( int inFile, int outFile )
   {
  return dounzip( inFile, outFile );
   }
  
  
   int CZip::HardWork( int inFile, int outFile )
   {
  return dozip( inFile, outFile );
   }
  </code></pre>
  
  <p>Output conf. type of this zip project is <strong>static library(.lib)</strong> </p>
  
  <p>I built this project and got zipdll.lib file.</p>
  
  <p>And in another project, I set necessary configurations like that additional library vs.</p>
  
  <p>and include header file. Finally my code is;</p>
  
  <pre><code> #include "czip.h"
   #pragma comment(lib, "zipdll")
   . 
   .
   .
   CZip oZip(sourceFile);
   oZip.SwapSize(targetFile);
  </code></pre>
  
  <p>When I built project, I got these errors;</p>
  
  <pre><code>  1&gt;c:\users\16481min\desktop\czip_demo\main.cpp(91): warning C4101: 'e' : unreferenced local variable
    1&gt;main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall CMamaZip::SwapSize(char const *)" (__imp_?SwapSize@CMamaZip@@QAEXPBD@Z)
    1&gt;main.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall CZip::CZip(char const *)" (__imp_??0CZip@@QAE@PBD@Z)
    1&gt;.\Debug\test_zip.exe : fatal error LNK1120: 2 unresolved externals
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
  </code></pre>
  
  <p>What is the problem? What I have to do?
  Any help?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>Main function:</p>
  
  <pre><code>#include "czip.h"
  #include &lt;string&gt;
  #include &lt;tchar.h&gt;
  #include &lt;wininet.h&gt;
  #pragma comment(lib, "wininet")
  #pragma comment(lib, "zipdll")
  
  
  typedef char OSC;
  
  using namespace std;
  void ZipSend(OSC *directory, OSC *ftpServerAddr, OSC *ftpUsername, OSC *ftpPassword);
  
   int main()
   {
  
  try 
  {     
   ZipSend("C:\\Users\\16481MIN\\Desktop\\Foto","10.100.47.23","ftptestuser","abcd+1234");
  }
  catch( CZipException e )
  {
      return -1;
  }
  return 0;
    }
  
    void ZipSend(OSC *directory, OSC *ftpServerAddr, OSC *ftpUsername, OSC *ftpPassword)
    {
  WIN32_FIND_DATA FindFileData;
  HANDLE hFind;
  
  OSC pattern[MAX_PATH];
      OSC sourceFile[MAX_PATH];
  OSC targetFile[MAX_PATH];
  
  memset(pattern, 0x00, MAX_PATH);
  sprintf(pattern,"%s\\*.*", directory);
  
  hFind = FindFirstFile(pattern, &amp;FindFileData);
  if (hFind == INVALID_HANDLE_VALUE) 
  {
  } 
  else 
  {
      do
      {
          if(_tcscmp(FindFileData.cFileName, TEXT("."))==0 || _tcscmp(FindFileData.cFileName, TEXT(".."))==0)
              continue;
  
          if(FindFileData.dwFileAttributes &amp; FILE_ATTRIBUTE_DIRECTORY)
          {
  
          }
          else
          {
               memset(sourceFile, 0x00, sizeof(sourceFile));
               memset(targetFile, 0x00, sizeof(targetFile));
  
               string strSourceFile(FindFileData.cFileName);
               int lastindex = strSourceFile.find_last_of("."); 
               string strTargetFile(strSourceFile.substr(0, lastindex));
  
               sprintf(sourceFile,"%s\\%s", directory, strSourceFile.c_str());
               sprintf(targetFile, "%s\\%s.zip", directory, strTargetFile.c_str());
  
               try 
               {
  
                  CZip oZip(sourceFile);
                  oZip.SwapSize(targetFile);
  
               }
               catch( CZipException e )
               {
               }
               try 
               {
                   OSC ftpFilePath[MAX_PATH] = "";
                   strcat(ftpFilePath, "/hobim/ASYADAN/");
                   strcat(ftpFilePath, strTargetFile.c_str());
                   strcat(ftpFilePath, ".zip");
  
               }
               catch(exception e)
               {
  
               }
  
  
          }
      }
      while (FindNextFile(hFind, &amp;FindFileData));
      FindClose(hFind);
  }
     }
  </code></pre>