Tips for cross-platform programming?

Discussion in 'Programming & Software Development' started by blankpaper, Nov 13, 2017.

  1. blankpaper

    blankpaper Member

    Joined:
    Feb 1, 2013
    Messages:
    889
    I'm going to convert my personal code projects from perl/python to a compiled language so I can pass it along to friends and acquaintances to use themselves in their line of work. They either use Linux (a few variants but mostly CentOS or ubuntu) or Windows, and I want to write software that's either natively cross-platform or easy to port. I want to use compiled code because I don't want them messing about with my code and complaining (and ultimately wasting my time). Also, I want to get more experience in programming for linux, since I have very little.

    It's a passion project as well as helping others so the juice is worth the squeeze, so to speak.

    The code has various inputs (email, inbound comms over listening TCP ports) and outputs (email, outbound TCP connections either with my code or controlling other installed software (e.g. SSH)). Internally it'll interact with a local mail daemon, web server and file handling (zip, file move/create/delete).

    Is the easiest way to just write C++ for linux and just ensure the Windows machines have Cygwin? This seems very convenient but also a bit of a cheat (for my educational purposes). Any other options?

    Also very keen to hear tips or things you've learned doing this sort of thing yourselves.
     
  2. GumbyNoTalent

    GumbyNoTalent Member

    Joined:
    Jan 8, 2003
    Messages:
    6,179
    Location:
    Briz Vegas
  3. waltermitty

    waltermitty Member

    Joined:
    Feb 19, 2016
    Messages:
    745
    Location:
    BRISBANE
    Use go, go binaries are portable and can be statically linked. There are nice libraries (and a package manager) for sockets, mailers etc.
     
  4. elvis

    elvis Old school old fool

    Joined:
    Jun 27, 2001
    Messages:
    33,874
    Location:
    Brisbane
    Most folks in that world are dumping wx for Qt.

    Python, and PyQT or PySide in particular are my votes. Caveat emptor: my entire industry defaults to those two tools across all OSes, so I have strong reinforcement bias about them.
     
    Last edited: Nov 13, 2017
  5. GumbyNoTalent

    GumbyNoTalent Member

    Joined:
    Jan 8, 2003
    Messages:
    6,179
    Location:
    Briz Vegas
  6. OP
    OP
    blankpaper

    blankpaper Member

    Joined:
    Feb 1, 2013
    Messages:
    889
    Very appreciative you 3 have posted, thanks.

    Forgot to say, my software has no GUI, maybe run as a service.

    Had a quick look at Go, looks good, but will need to read more. Am happy to pay a license if it's modest and allows me to freely distribute the software; it'll be worth the learning experience.
     
  7. Wolfje

    Wolfje Member

    Joined:
    Jul 9, 2007
    Messages:
    932
    Location:
    Brisbane
    First of all, there is _no such thing as a cheat_ when it comes to tooling, hammer for nails mate, you use what works :thumbup:

    Cross-platform native tools come in a few flavours:
    • MSVC - Microsoft's native C++ compiler for Visual Studio, the de facto Windows compiler
    • MinGW - Minimalist GNU for Windows - a port of g++ which is capable of generating native windows binaries without any emulation. Not a POSIX emulation layer, cannot be used to compile Linux-specific code on Windows. Good if you like the GNU toolchain but want to generate native win32 binaries with Windows-specific headers
    • Cygwin - Full POSIX emulation. Fairly messy, kind of slow and only really recommended if you're a sadist and you like causing yourself sigifciant pain every time someone calls you up with a "Program cannot start because cygwin1.dll cannot be found" error

    For cross-platform C and C++ projects I like to use a tool called CMake. CMake is kind of archaic but it takes in a CMakeLists.txt file with build directives will happily spit out unix makefiles, Visual Studio solution files, and MinGW Makefiles. From there you can build on whatever platform you like.

    In C++ it's pretty easy to stay away from non-portable code. Just use anything from the std namespace or use boost if that's your jam. Windows leak checking suuuucks so use Valgrind in Linux to sort out any leaks before even bothering to compile on Windows.

    Any compiler or platform-specific stuff commonly gets preprocessed out. Use #ifdef _MSC_VER.

    Cheers!
     
  8. Foliage

    Foliage Member

    Joined:
    Jan 22, 2002
    Messages:
    32,018
    Location:
    Sleepwithyourdadelaide
    Makes a big difference if you need a UI or not. If you don't need a UI then you can use basically any language, C++, C#, Python, Java, Go, Rust etc will all run on multi platforms. Also when you say multi platform do you mean mobile devices?

    The other option is you could use a web interface as your UI, then pull data from a database. This opens your options up even further.

    Personally I would stick to interpreted languages like C#, Java, Python etc if you are going multi platform. It is "easier", but not necessarily better.
     
  9. metamorphosis

    metamorphosis Member

    Joined:
    Feb 25, 2002
    Messages:
    1,645
    +1 for Mingw, however stable builds take a bit of searching, I recommend this:
    https://nuwen.net/mingw.html

    It's done by one of the MS guys. You'll find mingw tends to compile much faster code, when -02 and -march=native are used.
    Also codelite is the best cross-platform IDE for C++ I've come across, works well with Mingw:
    https://downloads.codelite.org/
     
  10. OP
    OP
    blankpaper

    blankpaper Member

    Joined:
    Feb 1, 2013
    Messages:
    889
    Yep, I've been leaning toward a web UI to set params or change config. Probably the easiest way to keep everyone happy. And no need for mobile devices specifically... if it works on mobile browsers, great, but if it's wonky I don't really care.

    Trying to steer clear of interpreted languages if I can, just opens up dramas for those with tinker-y minds.

    Go looks really cool, lots of people have nice blogs on it and it's easy to get info, but there's lots of alternatives in this thread, so lots more reading to do!
     
  11. Kremlin

    Kremlin Member

    Joined:
    Dec 23, 2001
    Messages:
    263
    Location:
    London
    Foliage mentioned Rust, which is a compiled language and uses LLVM underneath to produce binaries that will run on any combination of hardware and OS your friends run (you can also write your own OS with it if you want, but that's another issue).

    You can also set up a cross compiler for Rust and build binaries on your system to run on other systems. Feature-wise, you can do anything with C++ or C that you can do with Rust, but a lot of the language features make it a lot safer to program in (no more memory leaks or double-free bugs), so I'd recommend that if you are wanting to write close to the metal.
     

Share This Page