Compiling tinymudserver in Windows

Posted by Artel on Sat 09 Sep 2006 01:06 AM — 13 posts, 48,205 views.

USA #0
ie newbie
I have downloaded and installed cygwin, but I'm not sure what I do with it other than install it. Also, what is the best compiler to use for this? I'm using MSVC.NET, but maybe that's not the best for this.
Australia Forum Administrator #1
Make sure you have installed the development tools. That is, typing:

gcc --version

... should show something like:


$ gcc --version
gcc (GCC) 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)
Copyright (C) 2004 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.


rather than an error message.

You need to start up the "bash shell" that gets installed when you install cygin.

Now copy the tinymudserver_v2.tgz file into your "home" directory one way or another, and then from the bash shell unpack it:


tar xvzf tinymudserver_v2.tgz


That should create a directory "tinymudserver" with various files in it. Change to that directory:


cd tinymudserver


Then compile by typing "make:


make


That should create an executable.

I just tested it. That works, except because of tighter compiler rules I found I had to remove a semicolon from the end of lines 146, 208, 259, and 265. If you get an error you better edit the file tinymudserver.cpp and fix those lines up:



$ diff tinymudserver.cpp ../../tinymudserver/tinymudserver.cpp
146c146
<   };   // end of FindAndReplace
---
>   }   // end of FindAndReplace
208c208
<     };
---
>     }
259c259
<   void operator() (const T* ptr) const { delete ptr; };
---
>   void operator() (const T* ptr) const { delete ptr; }
260a261
>
265c266
<   void operator() (const T item) const { delete item.second; };
---
>   void operator() (const T item) const { delete item.second; }


Fixed lines in bold.

Amended on Sat 09 Sep 2006 01:50 AM by Nick Gammon
USA #2
For some reason gcc didn't install the first time. I did reinstall cygwin and gcc is now in there. My gcc --version looks identical to yours now.

make still does not work... just "command not found".
Australia Forum Administrator #3
Better install "make" then - that is one of the options under developer tools.
USA #4
Quote:
$ diff tinymudserver.cpp ../../tinymudserver/tinymudserver.cpp
146c146
< }; // end of FindAndReplace
---
> } // end of FindAndReplace
208c208
< };
---
> }
259c259
< void operator() (const T* ptr) const { delete ptr; };
---
> void operator() (const T* ptr) const { delete ptr; }
260a261
>
265c266
< void operator() (const T item) const { delete item.second; };
---
> void operator() (const T item) const { delete item.second; }


I seem to have completely different line numbers (using a win text editor)-- I think I removed the right semi-colons, but I still get errors. Just to be sure, where exactly is 208c208?
USA #5
I think that 208c208 means that it's line 208 of the 'left' file compared with line 208 of the 'right' file. Basically it's complaining about there being semi-colons after function definitions. The gcc suite is getting rather good at enforcing language standards, which might seem annoying but is actually a good thing because it forces people to write cleaner code.
Australia Forum Administrator #6
The line numbers should not be completely different, unless you are using a different version or something.

However you should only see one place in the source with:

// end of FindAndReplace

in it. If there is a semicolon after the } at the start of that line, that is the one to get rid of.

The place in your file should be roughly where the error message line points to.
USA #7
For some reason, when I open it in Notepad++, it doublespaces the lines which causes the odd line numbers, but I guess that makes then approximately double yours. Could the double spaces be causing errors?

When I try to make after fixing those semi-colons, I get a few errors ...

> make
g++ -g3 -Wall -w -pedantic -c tinymudserver.cpp
tinymudserver.cpp:135: error: expected `)' before '&' token
tinymudserver.cpp:135: error: expected `)' before '&' token
tinymudserver.cpp:135: error: expected `)' before '&' token
tinymudserver.cpp:135: error: expected `,' or `;' before '&' token
tinymudserver.cpp: In member function `tPlayer& tPlayer::operator<<(const T&)':
tinymudserver.cpp:411: error: expected primary-expression before ';' token
tinymudserver.cpp: In function `tRoom* FindRoom(const int&)':
tinymudserver.cpp:757: error: no matching function for call to `std::runtime_err
or::runtime_error()'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/stdexcept:109: note: candidates ar
e: std::runtime_error::runtime_error(const std::runtime_error&)
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/stdexcept:115: note:  std::runtime
_error::runtime_error(const std::string&)
tinymudserver.cpp: In member function `tPlayer* tPlayer::GetPlayer(std::istream&
, const std::string&, const bool&)':
tinymudserver.cpp:839: error: no matching function for call to `std::runtime_err
or::runtime_error()'
tinymudserver.cpp:781: note: candidates are: std::runtime_error::runtime_error(c
onst std::runtime_error&)
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/stdexcept:115: note:  std::runtime
_error::runtime_error(const std::string&)
tinymudserver.cpp: In function `void bailout(int)':
tinymudserver.cpp:861: error: `bStopNow' undeclared (first use this function)
tinymudserver.cpp:861: error: (Each undeclared identifier is reported only once
for each function it appears in.)
tinymudserver.cpp: In function `void DoShutdown(tPlayer*, std::istream&)':
tinymudserver.cpp:1787: error: `bStopNow' undeclared (first use this function)
tinymudserver.cpp: In function `void DoGoTo(tPlayer*, std::istream&)':
tinymudserver.cpp:1835: error: expected primary-expression before ',' token
tinymudserver.cpp: In function `void MainLoop()':
tinymudserver.cpp:2637: error: `bStopNow' undeclared (first use this function)
make: *** [tinymudserver.o] Error 1


I wanted to verify where exactly 208c208 was to make sure I didn't remove the wrong semi-colon...and a line of }; isn't exactly the rarest thing to find. Also, what did 260a261 indicate?
Australia Forum Administrator #8
Try Crimson Editor:

http://www.crimsoneditor.com/

That is freeware, and doesn't seem to have that problem.

Or, use vi in the bash shell.

Yes, adding extra lines might throw out compilation under certain circumstances.


// string find-and-replace
string FindAndReplace
  (const string& source, const string target, const string replacement)
  {
  string str = source;
  string::size_type pos = 0,   // where we are now
                    found;     // where the found data is
  if (target.size () > 0)   // searching for nothing will cause a loop
    while ((found = str.find (target, pos)) != string::npos)
      {
      str.replace (found, target.size (), replacement);
      pos = found + replacement.size ();
      }
  return str;
  };   // end of FindAndReplace  <-- line 146




  // output to player (any type)
  template<typename T>
  tPlayer & operator<< (const T & i)  
    {     
    outbuf += MAKE_STRING (i); 
    return *this; 
    };     <-- line 208




// see Josuttis p12 and Meyers p38
struct DeleteObject
  {
  template <typename T>
  void operator() (const T* ptr) const { delete ptr; };  <-- line 259
  };




// similar concept for maps
struct DeleteMapObject
  {
  template <typename T>
  void operator() (const T item) const { delete item.second; };  <-- line 265
  };



I must have added a blank line which is why 265 became 266.
Amended on Wed 13 Sep 2006 12:01 AM by Nick Gammon
USA #9
All right, this time I deleted the directory, reunpacked the file, and removed those semi-colons using Crimson Editor. There's no extra new lines now. I'm still getting several errors though:
> make
g++ -g3 -Wall -w -pedantic -c tinymudserver.cpp
tinymudserver.cpp:135: error: expected `)' before '&' token
tinymudserver.cpp:135: error: expected `)' before '&' token
tinymudserver.cpp:135: error: expected `)' before '&' token
tinymudserver.cpp:135: error: expected `,' or `;' before '&' token
tinymudserver.cpp: In member function `tPlayer& tPlayer::operator<<(const T&)':
tinymudserver.cpp:411: error: expected primary-expression before ';' token
tinymudserver.cpp: At global scope:
tinymudserver.cpp:516: error: extra semicolon
tinymudserver.cpp:527: error: extra semicolon
tinymudserver.cpp:534: error: `string' does not name a type
tinymudserver.cpp: In function `tRoom* FindRoom(const int&)':
tinymudserver.cpp:754: error: no matching function for call to `std::runtime_err
or::runtime_error()'
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/stdexcept:109: note: candidates ar
e: std::runtime_error::runtime_error(const std::runtime_error&)
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/stdexcept:115: note:  std::runtime
_error::runtime_error(const std::string&)
tinymudserver.cpp: In member function `tPlayer* tPlayer::GetPlayer(std::istream&
, const std::string&, const bool&)':
tinymudserver.cpp:836: error: no matching function for call to `std::runtime_err
or::runtime_error()'
tinymudserver.cpp:778: note: candidates are: std::runtime_error::runtime_error(c
onst std::runtime_error&)
/usr/lib/gcc/i686-pc-cygwin/3.4.4/include/c++/stdexcept:115: note:  std::runtime
_error::runtime_error(const std::string&)
tinymudserver.cpp: In function `void bailout(int)':
tinymudserver.cpp:858: error: `bStopNow' undeclared (first use this function)
tinymudserver.cpp:858: error: (Each undeclared identifier is reported only once
for each function it appears in.)
tinymudserver.cpp: In function `void DoShutdown(tPlayer*, std::istream&)':
tinymudserver.cpp:1784: error: `bStopNow' undeclared (first use this function)
tinymudserver.cpp: In function `void DoGoTo(tPlayer*, std::istream&)':
tinymudserver.cpp:1832: error: expected primary-expression before ',' token
tinymudserver.cpp: In member function `void tPlayer::ProcessRead()':
tinymudserver.cpp:2304: error: `Trim' undeclared (first use this function)
tinymudserver.cpp: In function `void MainLoop()':
tinymudserver.cpp:2634: error: `bStopNow' undeclared (first use this function)
make: *** [tinymudserver.o] Error 1


Any ideas?
Australia Forum Administrator #10
I just downloaded that file again, and unzipped it and put it into my Cygwin directory. I typed "make" and got this:


$ make
g++ -g3 -Wall -w -pedantic -c tinymudserver.cpp
tinymudserver.cpp:146: error: extra `;'
tinymudserver.cpp:208: error: extra semicolon
tinymudserver.cpp:259: error: extra semicolon
tinymudserver.cpp:265: error: extra semicolon
make: *** [tinymudserver.o] Error 1


I love these error messages. What is the difference between "extra ';'" and "extra semicolon"?

I removed those 4 semicolons, and typed "make" again and got this:


$ make
g++ -g3 -Wall -w -pedantic -c tinymudserver.cpp
g++ -g3 -Wall -w -pedantic -o tinymudserver tinymudserver.o

$ ./tinymudserver
Tiny MUD server version 2.0.0
Accepting connections from port 4000


The file I used was:

http://www.gammon.com.au/files/muds/tinymudserver_v2.tgz

I can't explain your errors - did you use that file?
USA #11
I didn't have the file in the cygwin directory at first. Everything is working now...thanks!
USA #12
Thought I should add this in case anyone tries this later on that when you try to compile tinymudserver_v2_2.tgz (the one with seperate source files) that in addition to removing those four semi-colons, you might need to add #include <sys/errno.h> to player.cpp and #include <fstream> to utils.h before it will compile under cygwin.