Unix [SOLVED]: Microsoft Visual Studio: Windows and Unix project source code compatibility

Unix [SOLVED]: Microsoft Visual Studio: Windows and Unix project source code compatibility

Home Forums Unix Unix [SOLVED]: Microsoft Visual Studio: Windows and Unix project source code compatibility

Tagged: , ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #37016

    Anonymous

    QuestionQuestion

    I’m going to develop a command line tool for both Windows and Unix OS architectures. However I’m facing a struggle. How can I make the code effectively transferrable between Windows and Unix?

    Project is going to be made in C++ language using primarily MS Visual Studio. However I want my tool be cross-platform, so I can use it both in Windows and Unix systems. Since Unix doesn’t support Visual Studio, I need to somewhat design the code structure to support both architectures (both being 32bit) and OS-specific headers need to be included for just the only one OS architecture the code is built in.

    So I am asking for your help. What is the most effective way to maintain pretty much the same code for both Windows and Unix, with all neccessary headers for that particular OS? So I can create program.exe file in Windows and program.run file in Unix? Some conditions to test current OS architecture (Windows or Unix) and include OS-dependent headers?

    What about encoding? Because Windows command line uses MS-DOS encoding (In Central Europe, it’s DOS codepage 852), and Unix terminal uses UTF-8 encoding. My tool will be multilingual (with contributors, starting with English and Czech languages from my side).

    I need to keep the code structure as small as possible, and of course easily maintainable. The source code shall be available for clone/fork from GitHub repository.

    If this is not the kind of question apropriate for Stack Overflow, then just tell and I’ll delete it. Just asking for help, nothing else.

    #37017

    Anonymous

    Accepted AnswerAnswer

    Step 1) set up your continuous integration system to build the code on Windows and Unix every time from day one. Preferably with multiple compilers on each platform.

    Step 2) Use a cross-platform build system like scons or cmake.

    Step 3) Don’t use any platform specific code in your program at all – and when you have to, implement multiple versions under various ifdef guards. Prefer using cross-platform libraries instead.

    Step 4) make sure you have plenty of unit tests (especially for the bits where you had to implement something multiple times using platform specific code) and make sure your CI system runs all the tests for every commit.

    Step 5) Make sure all text is UTF-8 encoded from day one – conversion to other encodings can happen at the display layer, but keep everything UTF-8 clean internally.

    Step 6) Do extensive manual testing on all supported platforms.

    And make sure to tweak every compilers warning setting waaay up and make warnings errors (and fix all such errors). What’s a warning with one compiler on one platform can often be silently miscompiled code with a different compiler on another platform.

    Source: https://stackoverflow.com/questions/47996616/microsoft-visual-studio-windows-and-unix-project-source-code-compatibility
    Author: Jesper Juhl
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.