9

I'm new in here and I still don't have a lot of experience and knowledge about Linux and software development.

I was thinking to start learning software and game development and I am currently building a PC in order to do that. I want to develop software or a game that has support with three major platform (Windows, macOS, and Linux).

Can I smoothly develop software or a game that support three major platforms from only one OS? Like if I use one Linux (with a lot of development tools in there) and want to develop software or game that also support Windows, macOS, and other Linux distribution, can I do that without facing a problem at later time like switching OS back and forth in order to testing it work or not? Or do I just need to install all the OSes (with all of the development tools in each OS) and build them in each OS for each support?

Peter Mortensen
  • 1,029
  • 1
  • 8
  • 10
Iqbal Nasrullah
  • 131
  • 1
  • 3
  • I suggest you start first with a text base linux program, then re-ask yourself the question. Jut compiling from linux a "hello world" program that run on windows is quit a challenge. – Archemar Apr 13 '23 at 11:03
  • 3
    @Archemar um no, it's not "quite a challenge", at least for you now that I can show you how to do it in a single line: `sudo dnf install -y mingw64-gcc; export CC=x86_64-w64-mingw32-gcc; echo '#include' > helloworld.c ; echo 'int main() { printf("hello world\\n"); return 0;}' >> helloworld.c; $CC -o helloworld.exe helloworld.c` (Of course, how you install mingw64-gcc depends on your distro, but the rest will be identical) – Marcus Müller Apr 13 '23 at 11:48
  • (on debianoids, it's a simple `sudo apt install gcc-mingw-w64-x86-64-win32` away) – Marcus Müller Apr 13 '23 at 11:52
  • @MarcusMüller is that enough? I guess you can make a simple "hello world" EXE. I thought GCC (including mingw) usually requires the standard libraries to be available in order to link against them? – Philip Couling Apr 13 '23 at 11:58
  • 1
    @PhilipCouling well, it again depends on your distro, but Fedora and similar have a relaviely nice selection of mingw development libraries your can just install; for example, getting mingw64-building Qt6 is one DNF command away. Same for things like all the classical boost, zlib, SDL, GTK, … libraries: prepackaged. If not, still just a normal build away, where you point the configuration script of whatever library at the mingw compilers and binutils. – Marcus Müller Apr 13 '23 at 12:03
  • (so, basically the same effort as if you built *any* library with a different than your system's default `cc`) – Marcus Müller Apr 13 '23 at 12:04
  • @MarcusMüller I'll try your exact command at home latter on. – Archemar Apr 13 '23 at 12:21
  • 2
    You might want to take a look at [godot](https://godotengine.org/), an open-source cross-platform game development engine that you can use to write 2D & 3D games that target Windows, Max, Linux, and mobile devices from the same code base. There are lots of tutorials available in blog posts and youtube videos. – cas Apr 13 '23 at 14:02
  • @PhilipCouling It may be possible to get the mingw cross-compiler under Linux to link static libraries, to avoid the generated Windows executable having any dependencies on mingw DLLs. I.e. create a cross-compiled Windows executable which only has dependencies on standard Windows DLL. [compile_windows_executable_under_linux](https://github.com/Chester-Gillon/plx_poll_mode_driver/blob/master/multi_platform_test/compile_windows_executable_under_linux.txt) contains some rough notes from a previous investigation into this if it helps. – Chester Gillon Apr 13 '23 at 18:31
  • 3
    @PhilipCouling You don't need the actual DLLs from Microsoft to be able to build a binary which links to them. MinGW comes with a full set of Win32 headers and import libraries (your distribution likely has packages like `mingw32-headers` and `mingw32-crt`), so the compiler will just grab symbol stubs from its bundled `libadvapi32.a` and produce a binary which will depend on an actual `advapi32.dll` to run. – TooTea Apr 13 '23 at 20:06
  • 1
    Minecraft Java edition is one example of a game that works on all platforms with no modifications. – slebetman Apr 14 '23 at 03:04
  • I'd second the use of godot, if you just want to write cross platform games. – Neil_UK Apr 15 '23 at 15:46

5 Answers5

13

Yes, of course, you can.

To do that, you need a universal language which can be understand on all target machines. Once you have such language - write a software on it, without using OS-specific code and you are done.

And guess what - there are tons of such languages, starting from C, C++, Java, and many-many more. And you can also use a multi-platform frameworks (language plus set of libraries and tools) to do a multi-platform projects.

What is even better, there are frameworks designed for multi-platform creation of games. The top on this list currently held by Unity. It would give you a lot of game-specific functionality and support for almost all modern OS's. Win/Max/Linux - in a free version of Unity, plus a dozen of other (including XBox/PlayStation/etc) in a commercial version.

White Owl
  • 4,511
  • 1
  • 4
  • 15
  • 29
    Defining C / C++ as universal languages is a bit misleading. The core language is universal, that's what C was designed to be. However no practical C program truly exists without interaction with the OS and Windows has never had any real overlap with Linux there. Compiled C programs are not portable between OS and cross compiling for Windows on a Linux platform is tricky. This is quite different to Java where the "compiled" program runs on a "JVM", and the OS specific JVM [Java virtual machine] provides OS specific boiler plate to allow one program to run. – Philip Couling Apr 13 '23 at 11:55
  • 2
    @Philip Couling: this is why a framework like Unity is recommanded here. With Qt you can also have a platform independent program (tested when using a program made for MacOS and compiled on Windows and on Linux). – Frédéric Loyer Apr 13 '23 at 12:08
  • 1
    @PhilipCouling, As I said already "without using OS-specific code". Of course writing multi-platform on C is tricky and not for a weak of heart. But it is still doable. Take `SDL` for example, and you can have almost as many OSes covered as with Unity. – White Owl Apr 13 '23 at 12:15
  • @WhiteOwl yeah I'm picking up on a nuance you may not have intended, but is there in your wording. You've put C / C++ / Java like these are somehow on a level. They are not. If you just start coding in C you are very likely to hit system dependant code really quickly. You MUST search for and use a system independant framework and MUST ensure you are compiling for each target platform. Languages like Java and Python let you just start coding and you are unlikely to hit platform dependant code without doing something "exotic". You don't need a platform independent framework with these. – Philip Couling Apr 13 '23 at 12:23
  • 1
    @WhiteOwl it's honestly that the most code people write these days is fairly platform agnostic – think about it: the whole glibc is *tiny* compared to say the whole of firefox. As consequence, software vendors spend sufficient time on their frameworks so that they performantly abstract away most of the system. The part of functionality of say a web browser, letter editor, 3D game or enterprise payroll and reimbursement system that really *needs* to deal with the nitty-gritties of each OS is really small, compared to what the development effort and code amount of the actual logic is. – Marcus Müller Apr 13 '23 at 19:25
  • @PhilipCouling but people in a development environment don't learn to write C from man pages. They learn to write C (or much more likely, C++) in a course that tends to lead them away from platform-dependent things towards well-abstracted libraries. You really don't need to learn how `openat` on Linux vs on Mac OS, vs whatever the Windows syscall is differ. You use your framework's `open_file` (or whatever it's called) function, or just stick to C++'s standard library, which is also fairly platform-independent. Honestly, I do a lot of relatively high-perf, heavily multithreaded C++: – Marcus Müller Apr 13 '23 at 19:28
  • @PhilipCouling yeah, I get to bite platform-specific problems often enough. But overall, the code necessary to make my favourite > 1 Million net lines of code C++ & Python project work on different platforms is really negligible compared to the overall hard logic. And that project is 19 years old – a lot of cruft from the time when platform-independent frameworks were much worse. Honestly, you can learn to be a competent C++ developer that produces commercially important C++ code without hitting a single case were OS matters. C isn't that much worse in general in portability – it's just that… – Marcus Müller Apr 13 '23 at 19:31
  • … someone doing C is probably not doing that to write modern platform independent software, but is writing low-level embedded (read: non-OS, or really slim RTOS) stuff, or operating system stuff themselves. But nobody learning how to "hello world" (maybe even with a graphical window, or a 3D context) is doing that! This luckily isn't the 1980/90s anymore: portability actually is a well-working principle. I mean, even microsoft with their own languages (.NET/C#/F#/Vb.net…) take this very far – .NET software runs pretty well cross-platform (lest you really do windows-specific stuff on purpose). – Marcus Müller Apr 13 '23 at 19:33
  • @MarcusMüller It would be more accurate to claim C has a wealth of platform indipendant frameworks. But I'm not convinced that this infers C is a platform indipendant language. I stress this might appear a pedantic point to some. – Philip Couling Apr 13 '23 at 20:10
  • @PhilipCouling I don't think you're being pedantic! But really, C is *designed* (and such is the libc) to allow for portable coding. It's one of C's selling points! Historically, at least. The fact that C is a really low-productivity / high-risk language in many modern applications really means that the *usage focus* of C has shifted to 1. legacy software (like your GNU coreutils, for example) and 2. low-level systems software as described above. Very few companies decide to write complex non-embedded applications in C in 2023 –and so the fact that you *can* write it portably is less prominent – Marcus Müller Apr 13 '23 at 20:12
  • @MarcusMüller haha it was Cs selling point in 1978. In 2023 it's hard to name a language that isn't platform indipendant under this definition besides assembly. And in those 45 years OS have evolved dramatically. Even basics like interprocess communication constructs are markedly different across OS and C itself does nothing to help you. Again there are a wealth of frameworks to bridge the gap. But it's the frameworks bridging the gap, not the language. – Philip Couling Apr 13 '23 at 20:20
  • @PhilipCouling I think I can agree to that, though C does have structs, and C99 and attributes like "packed" do allow for at least independent serialization. And if you allow yourself to believe that the POSIX standard is also meant to make C more interoperable, you get a whole load of data-normalizing, IPC-standardizing, network-abstracting interfaces! – Marcus Müller Apr 13 '23 at 20:38
  • 10
    I think this answer is missing a major sticking point though. Without at least VMs of the other environments (Windows and MacOS) it is going to be impossible to test on those systems. That is a recipe for disaster. Anyone developing cross-platform should have some kind of access to all the environments they plan to release on. The question asks if they need that specifically. – Tyler Shellberg Apr 13 '23 at 21:40
  • The assumption of how interesting a game can actually be without talking to the operating system is unrealistically optimistic. – Thorbjørn Ravn Andersen May 19 '23 at 14:18
8

The answer by @WhilteOwl is very nice, and I'd like to make some addition.

You can also try to learn HTML5/ES6/CSS3, which are Web programming technologies. You can use these to develop a kind of cross-platform software, that can run on desktop, tablet, TV set and hand-held devices.

You can host it on the web to save users from downloading stuff, and there's the ElectronJS Framework that you can use to build executables.

HTML and JavaScript have what I consider the easiest learning curve, although, back-end secure programming is a tough topic.

H5 ecosystem has more free reusable components than Unity I believe, and developing for this platform definitely doesn't require using proprietary tools.

Simple 2D games can be developed using Canvas API, and 3D games have WebGL and WebGL2 for support. There are also frameworks such as Three.js.

DannyNiu
  • 622
  • 5
  • 18
4

White Owl's answer, unfortunately, is overly optimistic. In theory, this is how things should work. In practice, it just isn't the case - or, at least, it is only so to a certain extent. There are numerous little problems and rabbits holes that await you if you attempt cross platform development.

For example, .NET is supposed to be cross platform, yet it doesn't support native GUI app development on Linux. Blazor should in theory work, yet I used to encounter Linux specific bugs. Also forget about Visual Studio, you only get Visual Studio Code, which is less feature packed and less convenient to set up.

To say that C and C++ are platform independent is... well, even less true. Philing Couling commented that:

Defining C / C++ as universal languages is a bit misleading. The core language is universal, that's what C was designed to be. However no practical C program truly exists without interaction with the OS and Windows has never had any real overlap with Linux there.

Even the core language is not fully universal, given differences in implementation defined behavior.

You can certainly try cross platfom development - but be wary of subtle problems that may and most likely will appear from time to time.

gaazkam
  • 1,400
  • 3
  • 10
  • 17
3

Windows, MAC and Linux are very different. Modern macOS (formerly known as OS X) does have some Unix-like roots, but it's whole GUI infrastructure is very different from that used on a typical Unix-like system.

There are languages and frameworks that try to abstract over the differences between operating systems, but those abstractions are not perfect. If you write a non-trivial program then it is very likely you will encounter bugs that only manifest themselves on a subset of target platforms, that you will have to write platform specific code to perform some operation that your framwork does not provide a cross-platform interface for or that you will want/need to use a library outside your framework that requires platform-specific techniques to interface with your framework.

plugwash
  • 4,242
  • 1
  • 18
  • 32
0

Yes, this is possible, as the other answers indicate.

What I'd like to add is that when developing a game, you are going to rely on a whole stack of software: you will be using one or more programming languages and software libraries and frameworks that implement basic functionality you want to use but not implement yourself.

Many of these stacks are suitable for cross-platform development, and you will need to pick one, depending on

  • hardware you want the game to run on (laptops? phones?)
  • the software environments you want it to run on (web-based? native GUI? text-based? should it be scriptable? etc.)
  • aesthetic and functional requirements you want the game to meet
  • performance requirements (easy to meet for tic-tac-toe, not so easy for a chess server with millions of users or for a first-person shooter)
  • your own experience

I think the best approach is hands-on:

  • find one or more open source games that look like games you'd want to spend time working on, and that are offered for Windows, MacOS, and Linux
  • figure out what it would take to develop and contribute a small improvement

That will take you through the whole software stack, build process, development process, and project communication requirements. Once you have an idea of what's required to make one tiny change to the kind of game you'd be interested in working on, you will have some perspective on what it would take to develop such a game.

Personally I've only contributed a few lines of code to only one game, namely Freeciv, which runs natively on Linux, Windows, MacOS, Android, and a few other OSes, and also has a web-based version. That is just one example; just Google for examples of multiplatform games and you'll probably find a few that look like the kind of game you'd want to work on.

reinierpost
  • 422
  • 1
  • 7
  • 16