Unresolved Externals

This is a discussion on Unresolved Externals within the C++ Programming forums, part of the General Programming Boards category; Howdy, I have a class called CONNECTION. Its class declaration is in the file Connection.Hpp. The definitions of its member ...

  1. #1
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986

    Unresolved Externals

    Howdy,

    I have a class called CONNECTION. Its class declaration is in the file Connection.Hpp. The definitions of its member functions are in the file Connection.Cpp.

    In my main file, main.cpp, I #include Connection.Hpp, and make calls to functions that are part of the CONNECTION class. When I compile, I get the errors:

    Code:
    main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CONNECTION::HandleRequest(void)" (?HandleRequest@CONNECTION@@QAE_NXZ)
    main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall CONNECTION::ReadRequest(void)" (?ReadRequest@CONNECTION@@QAE_NXZ)
    main.obj : error LNK2001: unresolved external symbol "public: __thiscall CONNECTION::CONNECTION(int,struct sockaddr_in)" (??0CONNECTION@@QAE@HUsockaddr_in@@@Z)
    Release/SWSBeta.exe : fatal error LNK1120: 3 unresolved externals
    Which pretty much says the function calls I made were not to functions that were linked.

    I am using VisualC++ 6.0, and both of the Connection.* files have been added. I don't understand why they are unresolved, just because they are called from main. What must I do to tell Connection.hpp that its member functions are all in Connection.cpp?

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Obviously the linking failed. He (a compiler is a "He", right?) found the declarations, otherwise he would've complained about undeclared functions. Are you sure you've included all files into your project? I see no reason why it would fail if you did.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Well, when I created the files, I went to File->New->Files and chose C/C++ Header File, made sure "Add to project" was checked and it was the right project, and then I came out and went to Project->Add to Project->Files... and selected the files, and it told me they were already in the project. So I have no idea why

    Edit: In main.cpp, should I include Connection.cpp as well as hpp?
    Last edited by nickname_changed; 08-30-2003 at 06:24 AM.

  4. #4
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Ok, originally I had both the class and method definitions in the same file. But this became too big and I guess it is considered the wrong way to do it, so I decided to split it up. As the single file it works perfectly, but as multiple (with the same code) it gets the errors.

  5. #5
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Ok, heres a quick overview:

    CONNECTION.HPP
    Code:
    #include....
    
    class CONNECTION 
    { 
      public: 
       CONNECTION(int SFD_SET, struct sockaddr_in);// Constructor 
       CONNECTION(); 
       bool LogConnection();         // Logs connection to the appropriate log 
       bool ReadRequest();         // Reads the request and sets values 
       bool HandleRequest();         // Handles the request 
    
      private: 
       // Methods 
       bool SetFileType();         // Sets if the file is a script or binary 
       bool IndexFolder();         // Indexes the folder by listing all the files 
       bool SendText();         // Sends the requested file if it is text 
       bool SendCGI();            // Sends the requested file if it is a script 
       bool SendBinary();         // Sends the requested file if it is binary 
       bool SendError();         // Outputs the appropriate error code 
       bool LogText(string);         // Logs some text. Used only for testing 
       string CalculateSize();         // Outputs the file size 
       bool ModifiedSince(string Date);   // Was the file modifed since... 
       bool UnModifiedSince(string Date);   // Is the file Unmodified since... 
    
       // Properties 
       int SFD;            // Socket descriptor of connection 
       struct sockaddr_in ClientAddress;     // Client address structure 
       VIRTUALHOST *ThisHost;         // This virtual host host 
    
       string FullRequest;         // The entire input from the client 
       string RequestType;         // Type of request (POST, GET etc) 
       string FileRequested;         // String folling GET 
         string QueryString;         // Anything after the '?' in the file 
         string Extension;         // Extension of file requested 
         string RealFile;         // Real path to file 
    
    etc etc....
    };
    Connection.Cpp
    Code:
    CONNECTION::CONNECTION(int SFD_SET, struct sockaddr_in CA)
    {
    	SFD = SFD_SET;												// Set the socket descriptor
    	ClientAddress = CA;											// Assign the client address
    	UseVH = false;												// Dont use a Virtual host by default
    	IsFolder = false;											// By default its not a folder
    	IsBinary = false;											// Nor is it binary
    	IsScript = false;											// Or a CGI script
    	IsAbsolute = false;											// And the URL is not an absolute URL
    	Status = 200;												// But the file is always served fine
    }
    
    etc etc... with all the members (yes all).
    Both files have the usual #ifdef SOMETHING #define SOMETHING etc, so that shouldn't be a problem.

    Maybe its because I gave them .hpp extensions rather than .h? Could that be the solution?

  6. #6
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Ok, I removed the #ifdefs from the cpp file, and now I get unresolved errors in a file that connection.hpp includes. Stupid things, I might just put it back to how it was. Argh!

  7. #7
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Ok, heres the three files and project/workspaces, don't worry about the headermap file (work in progress).
    Attached Files Attached Files

  8. #8
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    connection.cpp is missing
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  9. #9
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Crap, sorry about that guys, it was midnight last night when I posted that archive and I went to bed shortly afterwards. Here it is:
    Attached Files Attached Files

  10. #10
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Thanks heaps Salem!

    Unfortunately, I opened the workspace and tried to compile (as Release) and got this:

    Code:
    --------------------Configuration: SWSBeta - Win32 Release--------------------
    Compiling...
    connection.cpp
    main.cpp
    Linking...
    connection.obj : error LNK2001: unresolved external symbol "class OPTIONS  Options" (?Options@@3VOPTIONS@@A)
    main.obj : error LNK2001: unresolved external symbol "class OPTIONS  Options" (?Options@@3VOPTIONS@@A)
    connection.obj : error LNK2001: unresolved external symbol "class VirtualHostIndex  VHI" (?VHI@@3VVirtualHostIndex@@A)
    connection.obj : error LNK2001: unresolved external symbol "class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >  __cdecl IntToString(int)" (?IntToString@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2
    @@std@@H@Z)
    connection.obj : error LNK2001: unresolved external symbol "int __cdecl CalcMonth(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >)" (?CalcMonth@@YAHV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@
    @@Z)
    main.obj : error LNK2001: unresolved external symbol "public: bool __thiscall OPTIONS::ReadSettings(void)" (?ReadSettings@OPTIONS@@QAE_NXZ)
    Release/SWSBeta.exe : fatal error LNK1120: 5 unresolved externals
    Error executing link.exe.
    
    SWSBeta.exe - 7 error(s), 0 warning(s)
    Do you have any idea why? Did this happen on yours? Maybe I changed something in my VC++ settings

  11. #11
    Banned nickname_changed's Avatar
    Join Date
    Feb 2003
    Location
    Australia
    Posts
    986
    Scratch that, I hadn't added headermap.cpp and options.cpp to the project, it compiles perfectlt now, thanks Salem!! I don't know what I'd do without you, your a god!

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. unresolved externals??
    By pokiepo in forum C Programming
    Replies: 6
    Last Post: 07-02-2008, 12:38 PM
  3. C++ std routines
    By siavoshkc in forum C++ Programming
    Replies: 33
    Last Post: 07-28-2006, 01:13 AM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 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