CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jan 2009
    Posts
    32

    Unidentified reference when incuding header file

    I have three file:

    Drupal.h
    Drupal.cpp
    install.cpp

    When including the Drupal.h file in the install.cpp file and compiling, everything is 100%, but when I try to run I get the following error:

    Code:
    C:\DOCUME~1\andrel\LOCALS~1\Temp/ccghcaaa.o(.text+0xe):install.cpp: undefined reference to `Drupal::copy_drupal_files_WindowsXP()'
    collect2: ld returned 1 exit status
    When I include the Drupal.cpp file in the install.cpp file, everything works 100%. Am I doing something wrong, I'm sure I'm not supposed to include the cpp file but the h file.

    See my three files below:

    Drupal.h
    Code:
    /**
    // Author: Andre Lombaard
    // Date: 21/03/2009
    */
    
    #ifndef DRUPAL_H
    #define DRUPAL_H
    
    class Drupal
    {
    	public:
    		void copy_drupal_files_WindowsXP();
    };
    
    #endif
    Drupal.cpp
    Code:
    /**
    // Author: Andre Lombaard
    // Date: 21/03/2009
    // Class: Copy the drupal files to the server/host folder and update the database
    */
    
    #include <iostream>
    #include <windows.h>
    #include "Drupal.h"
    
    using namespace std;
    
    /**
    Autohor: Andre Lombaard
    Date: 23/03/2009
    Function: A function that was developed in to copy all the files contained in the drupal folder to a new destination specified on the C: drive
    Operating system: Windows XP
    */
    void Drupal::copy_drupal_files_WindowsXP()
    {
    	SHFILEOPSTRUCT sf; 
    	memset(&sf,0,sizeof(sf));
    	sf.hwnd = 0;
    	sf.wFunc = FO_COPY; //Set the wFunc member to COPY
    	sf.pFrom = "C:\\UEPS report manager installer\\drupal\\drupal-6.8\\*.*\0\0"; //The destination to copy from
    	sf.pTo = "C:\\UEPS report manager installer\\drupal\\wamp\\drupal-6.8\0\0"; //The destination to copy to
    	sf.fFlags = FOF_NOCONFIRMATION | FOF_NOCONFIRMMKDIR | FOF_SIMPLEPROGRESS;
    	int n = SHFileOperation(&sf);
    	if( n == 0)
    	{        
    		cout << "Success\n";    
    	}
    	else    
    	{        
    		cout << "Failed\n";    
    	}
    }
    install.cpp
    Code:
    /**
    // Author: Andre Lombaard
    // Date: 21/03/2009
    // Class: Execute the UEPS report manager installer application
    */
    #include "Drupal.h"
    
    using namespace std;
     
    int main()
    {
    	Drupal d;
    	d.copy_drupal_files_WindowsXP();
    	return 0;
    }
    Any help is much appreciated

  2. #2
    Join Date
    Mar 2009
    Location
    Granada, Spain
    Posts
    40

    Re: Unidentified reference when incuding header file

    Is Drupal.h in the same directory as install.cpp?

    I don't see anything wrong. How are you compiling it?

  3. #3
    Join Date
    Jan 2009
    Posts
    32

    Re: Unidentified reference when incuding header file

    Yes they are in the same directory. I'm compiling using SciTe, so I just press Ctrl+F7

  4. #4
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: Unidentified reference when incuding header file

    install.cpp: undefined reference to `Drupal::copy_drupal_files_WindowsXP()'
    collect2: ld returned 1 exit status
    When including the Drupal.h file in the install.cpp file and compiling, everything is 100%, but when I try to run I get the following error:
    That looks like a compilation error rather than runtime.
    Are you sure you get this error after you run it?

  5. #5
    Join Date
    Mar 2009
    Location
    Granada, Spain
    Posts
    40

    Re: Unidentified reference when incuding header file

    Try manual compiling:
    Code:
    g++ install.cpp drupal.cpp -o install
    (I agree with potatoCode).

  6. #6
    Lindley is offline Elite Member Power Poster
    Join Date
    Oct 2007
    Location
    Seattle, WA
    Posts
    10,895

    Re: Unidentified reference when incuding header file

    Some compilers use "zero-link" builds where all linker dependencies are resolved at runtime. That could explain what's being seen.

    They key is that .h files have nothing to do with linker errors. Those arise because you aren't compiling both source files.

  7. #7
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: Unidentified reference when incuding header file

    Quote Originally Posted by Lindley View Post
    Some compilers use "zero-link" builds where all linker dependencies are resolved at runtime. That could explain what's being seen.
    Hi Lindley!
    Aha I see, I didn't know about that.
    Thanks!

  8. #8
    Join Date
    Jan 2009
    Posts
    32

    Re: Unidentified reference when incuding header file

    Thank you Lindley

    You were right, I compiled both the files and everything is working now! Guess that is why it is best practice to use a MAKEFILE right?

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured