c++ source code on linux server and windows client?

This may be a really dumb question, but I hope to be able to clearly express myself.

My daughter has a multi-player game source code. For years, she's used Visual C++ to compile the game for Windows. There is a server exe file and a client exe file, which works well if using a Windows server.

What I want to know is, is it possible to compile the server file to use on a linux server and keep the client exe files for windows? Or would there be a compatibility issue?

Thank you.

Answers


What I want to know is, is it possible to compile the server file to use on a linux server and keep the client exe files for windows?

Yes, it's possible. In fact this sort of thing is done all the time. I do it for a living. In order to accomplish this, you must do two things:

  1. Write the code in the first place using only Standard-compliant idioms, syntax and functions. This can also be accomplished by using 3rd party libraries that are compatible with both Windows and Linux, such as Boost.

  2. Compile the code on the target hardware.

Step 2 is arguably the easiest. All you need is access to a linux machine with a linux compiler, such as g++, and let 'er rip. You'll need to set up your own makefiles and such in most cases. Usually a tool such as CMake is used to accomplish this.

Step 1 is much harder. Code that is legitimately compilable on multiple platforms (such as Windows & Linux) is called "portable." Writing portable code is easy enough if you are focused on doing this from the outset. Retrofitting portability, on the other hand, can be a gargantuan task. Many projects are abandoned completely because of this hurdle. If your daughter hasn't been writing portable code from the start, there's a very good chance that making it portable is a near-impossibility.

I'm not trying to dissuade you from the attempt. In fact I'd encourage you to take it on. In my experience, making a platform-specific piece of software portable is one of the harder things for a programmer to do correctly, but even if the project is ultimately a failure the effort reaps its own rewards by making them a better programmer. In order to write portable code one needs to have a fairly solid grasp on the language at a brass-tacks level. Programmers who can write portable code are very often (not always) more skilled than their platform-specific counterparts.

As far as compatibility issues are concerned, the only real 'gotcha' that comes to mind is endianness. Especially in a client/server type system, you'll need to tacke this sooner rather than later.


Hard to say, C++ compilers are hardware specific (as opposed to Java), Your best bet is to try and just compile it on a linux distro C++ editor. See what errors you get and troubleshoot from there...

Good Luck


It depends. I doubt you will be able to port that Windows code directly to Linux and just recompile. The IPC (Inter-process communication) between the server and client is likely written using Windows procedures and would have to be changed for Linux. I'm fairly certain they use different calls for different platforms.

Of course, if you have the source you can make these changes yourself but it will likely require some debugging.

Info on Linux sockets: http://www.linuxhowtos.org/C_C++/socket.htm

Info on Windows sockets: http://msdn.microsoft.com/en-us/library/windows/desktop/ms740673(v=vs.85).aspx


There are several approaches you might take. Each has a unique set of tradeoffs and benefits.

  1. Rewrite the code to compile on Linux using native services. Difficulty +++, benefits +++
  2. Rewrite the code to use a platform-independent library which provides needed services. Difficulty ++, benefits +++
  3. Run the .exe code in a Linux-hosted virtual machine running Windows. Not difficult, benefits ++
  4. Run the .exe on Linux using Wine a compatibility layer which translates Windows calls into Linux equivalents. For many properly written Windows programs, this works quite well. Not difficult, benefits ++

Each of these requires some degree of education either for learning a new programming environment or determining proper configuration and changes in operability. There are plenty of free forums for support for all.


Need Your Help

Catch "Could not open connection to gateway" in sshtunnel.py

python ssh paramiko

Every now and then setting up a tunnel using sshtunnel.py fails because the gateway (ssh_host) complains the first time I connect to it. I would like to give it a few retries before giving up:

CommandBars.FindControl throwing an exception

ms-word vsto add-in

I am trying to use the FindControl Method of the CommandBars object in a VSTO Word addin to get what else a command bar object