Heya folks, this is my first post in here, hope you gurus out there can help me out:
I'm programming a very basic web server (college task in networking).
my project currently has 3 files:
webserver.cpp - Which contains the main, and various socket related functions.
webserver-engine.cpp - Which contains all HTTP protocol parsing functions, and other functions which are responsible for setting up HTTP responses from the server.
webserver-engine.h - Which contains all webserver-engine.cpp functions declarations, plus all of the project's consts and structs. This file is #included in both the webserver-engine.cpp and webserver.cpp files above.
Problem is that I get the following errors:
Code:Error 26 fatal error LNK1169: one or more multiply defined symbols found C:\Users\Mikey Shiran\Documents\Visual Studio 2008\Projects\Semester 3\Comm\WebServer\Debug\WebServer.exe 1 Error 24 error LNK2005: "char const * const SERVER_NAME" (?SERVER_NAME@@3PBDB) already defined in webserver.obj webserver-engine.obj Error 25 error LNK2005: "char const * const HTTP_VERSION" (?HTTP_VERSION@@3PBDB) already defined in webserver.obj webserver-engine.obj Error 23 error LNK2005: "char const * const HOME_DIR" (?HOME_DIR@@3PBDB) already defined in webserver.obj webserver-engine.obj Error 22 error LNK2005: "char const * * MONTH" (?MONTH@@3PAPBDA) already defined in webserver.obj webserver-engine.obj Error 21 error LNK2005: "char const * * DAY" (?DAY@@3PAPBDA) already defined in webserver.obj webserver-engine.obj Error 20 error LNK2005: "char const * * CONTENT_TYPE" (?CONTENT_TYPE@@3PAPBDA) already defined in webserver.obj webserver-engine.obj
webserver-engine.h looks likes this:
And i've checked that both the engine and main files aren't defining the above variables inside them.Code:#ifndef _WEBSERVER_ENGINE_H_ #define _WEBSERVER_ENGINE_H_ #include <iostream> using namespace std; #include <stdio.h> #include <winsock2.h> const int MAX_BUF_SIZE = 256; typedef struct contentInfo { int typeIndx; int statusIndx; int length; char* requestedPath; FILE* currFile; char shortData[MAX_BUF_SIZE]; bool isHeadReq; bool readFile; bool headerSent; } ContentInfo; struct SocketWhat { SOCKET id; // Socket handle int whatR; // Receiving? int whatS; // Sending? char buffer[MAX_BUF_SIZE]; int len; bool closeCon; contentInfo content; }; typedef struct status { int code; char* msg; char* htmlCode; } Status; const int TYPE_UNKNOWN = -1; const int TYPE_HTML = 0; const int TYPE_CSS = 1; const int TYPE_JPG = 2; const int TYPE_PNG = 3; const int TYPE_GIF = 4; const char* CONTENT_TYPE[5] = { "text/html", "text/css", "image/jpeg", "image/png", "image/gif" }; const int STATUS_ERR_NOT_FOUND = 0; const int STATUS_ERR_NOT_IMPLEMENTED = 1; const int STATUS_OK = 2; const Status HTTP_STATUS[3] = { {404, "Not Found", /* MAKE SURE THIS IS NOT LONGER THAN MAX_BUF_SIZE */ "<html><title>ERROR 404 - File Not Found</title><body><h2>ERROR 404 - The file you requested was not found on this server.</h2></body></html>"}, {501, "Not Implemented", /* MAKE SURE THIS IS NOT LONGER THAN MAX_BUF_SIZE */ "<html><title>ERROR 501 - Request Type Not Implemented</title><body><h2>ERROR 501 - Your request is not supported by this server</h2></body></html>"}, {200, "OK", NULL} }; const int MAX_DATE_LEN = 32; const char* DAY[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"}; const char* MONTH[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; const char* HOME_DIR = "D:/WebServer"; const char* SERVER_NAME = "MSCK WebServer v0.1"; const char* HTTP_VERSION = "1.1"; const int DEFAULT_BUF_SIZE = 512; const int MAX_CONTENT_HEAD_SIZE = 140; char* parseReqGenerateHeader(struct SocketWhat& sock); char* generateHeader(ContentInfo& content); char* getTimeAndDateAsStr(); int getContentTypeIndx(char* filePath); void strToLower(char* src); char* getCompleteFilePath(char* path); long getFileSize(FILE* filePntr); void cleanContent(ContentInfo& content); void setErrorContent(ContentInfo& content, int statusErr); char* findInHeader(SocketWhat& sock, char* str); void printTokens(char* str, char* delim); #endif
Any ideas how to solve this?
Thanks alot!
Mikey


