Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ source code on linux server and windows client? [closed]

Tags:

c++

linux

windows

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.

like image 881
user3267607 Avatar asked Sep 11 '26 10:09

user3267607


1 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.

like image 76
John Dibling Avatar answered Sep 12 '26 23:09

John Dibling