The question's description will evolve depending on requested information or evolution of answers.
I made this C++ server for a game, which works on Windows, and would like to make it cross-platform, so it at least works on Linux (Ubuntu), macOS would be a plus i'd really appreciate, but not indispensably necessary (specially if single "cross-platform executable" isn't a possibility).
The server was programmed using VisualStudio IDE. These are all my source files I copied to another directory, including a custom static library (this one is in the same directory, the rest are all in C:/libraries):
Project dependencies are the following as configured in VisualStudio:
All libraries are to be linked statically. These are the ones my server uses:
- GLM: Header only, cross platform.
- Cereal: Header only, cross platform.
- SFML modules: Can be linked statically. Cross platform according to them, even though this surprises me, since, for example, sfml_network module depends on winsock, which is a windows library...
- MORPH_Shared_functions, My own library: Is static. It's own dependencies are the same as already listed for server, so I'm asuming that would make it cross-platform.
The entire server fits in a single executable without dynamic library dependencies. I tried moving the exe to another computer, and it works fine without the libraries installed in the system since they're merged into the executable.
According to the first answer I got, Every platform should be considered separately. So I'm focusing on Linux/Ubuntu first:
- Progress 1:
Begining with Ubuntu, I tried the g++ compiler for windows. I installed it on windows by installing MinGW, and now I can use it from windows's cmd. I tried following this nice and simple guide: https://courses.cs.washington.edu/courses/cse373/99au/unix/g++.html
From what I read, I understand a propper approach would be first compiling each .cpp individually, so I made myself a list of commands:
g++ -c -o Game.o Game.cpp g++ -c -o CommandManager.o CommandManager.cpp g++ -c -o ServerPlayer.o ServerPlayer.cpp g++ -c -o ServerProp.o ServerProp.cpp g++ -c -o ServerWorldState.o ServerWorldState.cpp g++ -c -o UDP_Server_CS.o UDP_Server_CS.cpp
then I would do something like:
g++ -Wall -o MORPH_Server -Xpreprocessor SFML_STATIC -I MORPH_Shared_Functions -I C:\libraries\SFML\SFML-2.5.1\include -I C:\libraries\GLM\glm -I C:\libraries\CEREAL -L C:\libraries\SFML\SFML-2.5.1\extlibs\libs-msvc\x64 -L C:\libraries\SFML\SFMLx64SourceAndCompile\lib\Debug -l MORPH_Shared_Functions.lib -l winmm.lib -l ws2_32.lib -l sfml-system-s-d.lib -l sfml-network-s-d.lib Main.o Game.o CommandManager.o ServerPlayer.o ServerProp.o ServerWorldState.o UDP_Server_CS.o
In order to link them all together
However, the first individual module compilation attempt (Game.cpp) results in a header from my custom shared library not being found with error:
In file included from Game.h:2:0, from Game.cpp:1: UDP_Server_CS.h:1:33: fatal error: udp_network_manager.h: No such file or directory #include "udp_network_manager.h"
I really don't know if I should link all libraries for each compiled module, so for now I at least tried:
g++ -c -o Game.o -lMORPH_Shared_Functions.lib Game.cpp
In order to point to my shared library, hopefully helping with pointing to it's header, but this returns the same error.
I imagine if I continued with this approach (which works for ubuntu, and no other OS's I know of), I'd first try to get the commands right for compiling, and then I could try making visual studio compile with CMake using that same commands, or something like that. I don't know too much about cmake, I only used it for compiling some libraries like sfml a few times.
Note: I already did a similar question some weeks ago (How to remotely host my c++ game server on Ubuntu?). This one is based on the same objective, but with more specifics on the case, and some actual strategies already developed. In general I'm still looking for advice, ideas, and even specific guides.