-
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?
-
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.
-
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?
-
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.
-
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?
-
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!
-
Ok, heres the three files and project/workspaces, don't worry about the headermap file (work in progress).
-
connection.cpp is missing
-
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:
-
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 :(
-
Scratch that, I hadn't added headermap.cpp and options.cpp to the project, it compiles perfectlt now, thanks Salem!!:D I don't know what I'd do without you, your a god!