Annoying problem...

"Spam" <[email protected]> Sat, 19 Oct 2002 15:19:50 -0400
Newsgroups gmane.comp.gcc.cgicc.general
Message-ID <000101c277a4$82c8ba10$19354742@computer>
Ok, here is my situation:  I am in the process of creating a Text
Database that will use XML files to imitate a database.  It will be used
in CGI applications.  I created a very simple structure on my own
computer using Microsoft Visual Studio 6.  Then, all I want to do is
upload those files, and use g++ on the server to compile the code into
the actual CGI file.  The whole thing works perfectly fine on my
computer, but when I try to use g++, I get the following errors:

bash-2.05$ g++ try.cpp
/tmp/ccACQPoE.o: In function `main':
/tmp/ccACQPoE.o(.text+0x2e): undefined reference to
`textdb::TextDB::TextDB(void)'
/tmp/ccACQPoE.o(.text+0x57): undefined reference to
`textdb::TextDB::connect(basic_string<char, string_char_traits<char>,
__default_alloc_template<true, 0> >)'
/tmp/ccACQPoE.o(.text+0x149): undefined reference to
`textdb::TextDBException::TextDBException(textdb::TextDBException const
&)'
collect2: ld returned 1 exit status

Here are all of the files.  There are 5 in all, and each file is noted:

PLEASE, any help will be very appreciated, I spent all yesterday
searching the internet for a possible solution to this, and I couldn't
find anything.  Is it a problem with the linker or something?

here is my g++ version:

bash-2.05$ g++ -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-108.7.2)

***********
* try.cpp *
***********

#include <string>
#include <cstdio>
#include "textdb.h"
#include "textdbex.h"

using namespace std;

int main() {
	printf("Content-type: text/html\n\n");
	
printf("<html>\n<head>\n<title>TextDB</title>\n</head>\n<body>\n");
	try {
		textdb::TextDB db;
		db.connect("");
	} catch(textdb::TextDBException &ex) {
		printf("TextDBConnectionException: %s",ex.what());
		throw ex;
	}
	printf("\nWorks");
	printf("\n</body>\n</html>\n");
	return 0;
}

************
* textdb.h *
************

#ifndef _TEXTDB_H
#define _TEXTDB_H

#include <string>
#include "textdbex.h"

using namespace std;

namespace textdb {
	class TextDB {
		public:
			TextDB();

			void connect(string directory);
		protected:
			string db_location;
	};
}

#endif

**************
* textdb.cpp *
**************

#include <string>
#include "textdbex.h"
#include "textdb.h"

using namespace std;

namespace textdb {
	TextDB::TextDB() {
		db_location = "";
	}

	void TextDB::connect(string directory) throw(TextDBException) {
		if(directory == "") {
			throw TextDBConnectionException("Database
directory not provided.");
		}
	}
}

**************
* textdbex.h *
**************

#ifndef _TEXTDBEX_H
#define _TEXTDBEX_H

#include <string>

using namespace std;

namespace textdb {
	class TextDBException {
		public:
			TextDBException();
			TextDBException(const string &);
			TextDBException(const TextDBException &);
			virtual const char* what() const {return
msg.c_str();};

		protected:
			string msg;
	};

	class TextDBConnectionException : public TextDBException {
		public:
			TextDBConnectionException();
			TextDBConnectionException(const string &);
			TextDBConnectionException(const
TextDBConnectionException &);
	};
}

#endif

****************
* textdbex.cpp *
****************

#include <string>
#include "textdbex.h"

using namespace std;

namespace textdb {
	/*
		TextDBException Class
	*/
	TextDBException::TextDBException() {
		msg = "";
	}

	TextDBException::TextDBException(const string &_msg) {
		msg = _msg;
	}

	TextDBException::TextDBException(const TextDBException &tdbe) {
		msg = tdbe.msg;
	}

	/*
		TextDBConnectionException Class
	*/
	TextDBConnectionException::TextDBConnectionException()
		: TextDBException()
	{}

	TextDBConnectionException::TextDBConnectionException(const
string &_msg)
		: TextDBException(_msg)
	{}

	TextDBConnectionException::TextDBConnectionException(const
TextDBConnectionException &_tdbce)
		: TextDBException(_tdbce)
	{}
}