Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

So far all my development in C++ has been targeted to Windows, however I have always had it in the back of my mind that I will someday be targeting Linux. I am aware therefore of the need to select cross-platform libraries, and to keep my code as portable as possible (or provide alternative implementations for code which isn't portable). This question therefore does not relate to issues of code compilation.

I would like to know, what are some common issues that a developer will face when targeting both Linux and Windows? In particular, but not limited to:

  1. Best practices for handling configuration files. On Windows it seems this is fairly arbitrary - I've seen software store their configuration inside the program folder, in the user's folder (under appData), and in the registry. On Linux it seems much more heavily weighted towards dedicated configuration folders (/etc). How should I handle these differences in my code? Do I hard code the locations, or is there some system-defined function I can consult?

  2. Same as (1) but for logging.

  3. How do I go about keeping my project files in sync? E.g. if I update something in a Visual Studio project file, do I generally need to manually update the equivalent thing in whatever Linux environment I'm working in, or is there a commonly used method of avoiding this?

  4. What is the best way to handle platform implementation differences in my code? Should I use #ifdefs, or should I keep the platform-specific code in separate files and have the project specify which files are included?

  5. Anything else I haven't thought of which I should start considering / researching?

share|improve this question

closed as not constructive by Robert Harvey, Dynamic, Glenn Nelson, Martijn Pieters, gnat Jan 14 '13 at 21:40

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.If this question can be reworded to fit the rules in the help center, please edit the question.

1  
What build system do you use? Or is this totally VS based? –  jozefg Jan 14 '13 at 20:31
    
@jozefg VS on Windows, but I haven't yet decided on a Linux build system and/or IDE. –  Jon Bentley Jan 14 '13 at 20:35
3  
It might be worth looking into CMake or similar, mostly because you don't want to be tied to visual studios if your going to ship for linux. If you keep the same build system for both platforms there's much less pain –  jozefg Jan 14 '13 at 20:39
1  
/etc is standard place for configuration only for system-wide services or network services. User applications should keep their stuff in .(name-of-app)/ or .config/name-of-app/ in user home directory. –  Hubert Kario Jan 14 '13 at 20:43
1  
@JonBentley For a server application, this sounds like a system-wide application so the config files will go in /etc. –  DFord Jan 14 '13 at 21:02
show 2 more comments

1 Answer

up vote 1 down vote accepted
  1. Emplacement of things. See the Filesystem Hierarchy Standard. Quick summary for configuration: machine configuration under /etc/opt/<package>, user configuration under $HOME/.<package>.

  2. Logging, it means different things for different people. For a system tool, look syslog

  3. That's the job of you VCS and shouldn't be very different from keeping several Windows machines in sync.

    1. Find a library which provides an abstraction (starting with boost for instance)
    2. Build such a library.
    3. Use #ifdef for minor differences, for bigger things, see 2 if you can't find 1.
  4. It is common to install server applications with their own user as a security measure. Look also for chroot.

share|improve this answer
    
Thanks for the answer. For 3, I meant in terms of the fact that I'll probably be using two different build systems with their own project file formats (as opposed to keeping two environments synced with the exact same project file). E.g. on Windows it might be a VS project file and on Linux it might be a Qt .pro file (perhaps bad example, but it makes the point). Should I be making changes in both manually or is there a cross platform format I could use, that could convert to a VS project etc as needed. –  Jon Bentley Jan 15 '13 at 0:37
    
There are several build systems which want to be system independant. Qt .pro is one (so if you intend to use it for Linux, investigate using it for Windows as well), cmake is another but they are far from being the only one (as a matter of fact, one could argue that they are too many and by consequence that the effort is too dispersed) –  AProgrammer Jan 15 '13 at 7:57
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.