Re: help-cgicc digest, Vol 1 #127 - 1 msg
Charles Tassell <[email protected]> Mon, 21 Oct 2002 15:49:02 -0300
| Newsgroups | gmane.comp.gcc.cgicc.general |
|---|---|
| Message-ID | <[email protected]> |
The problem is your compile command. You have to include all the C++ files, as the try.cpp is only including the header files, not the actual C++ code. Try something like: g++ -o try try.cpp textdb.cpp textdbex.cpp or, the more common method: g++ -c -o textdb.o textdb.cpp g++ -c -o textdbex.o textdbex.cpp g++ -o try try.cpp textdb.o textdbex.o The -c means that this is an object file, so it doesn't require a main() routine and it shouldn't be sent to the linker. -o just specifies the name of the output file. At 07:41 AM 10/21/2002, [email protected] wrote: >Send help-cgicc mailing list submissions to > [email protected] > >To subscribe or unsubscribe via the World Wide Web, visit > http://mail.gnu.org/mailman/listinfo/help-cgicc >or, via email, send a message with subject or body 'help' to > [email protected] > >You can reach the person managing the list at > [email protected] > >When replying, please edit your Subject line so it is more specific >than "Re: Contents of help-cgicc digest..." > > >Today's Topics: > > 1. Annoying problem... (Spam) > >--__--__-- > >Message: 1 >Reply-To: <[email protected]> >From: "Spam" <[email protected]> >To: <[email protected]> >Date: Sat, 19 Oct 2002 15:19:50 -0400 >Subject: [help-cgicc] Annoying problem... > >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) > {} >} > > > > > > >--__--__-- > >_______________________________________________ >help-cgicc mailing list >[email protected] >http://mail.gnu.org/mailman/listinfo/help-cgicc > > >End of help-cgicc Digest