Thread: Writing portable code

  1. #1
    Registered User
    Join Date
    Nov 2011
    Posts
    83

    Writing portable code

    Hi,

    I would like to know portable way of setting up libraries and dependencies, and set up projects settings automatically. I am confused whether is CMake or Premake that I should learn.

    Could someone shed some lights on this and give me some few pointers to get started.

    Regards,
    Swoorup Josh

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    The make system is only one part of the portability problem.

    Example.
    You have a game written using the SDL library. It is compatible with code::blocks on Linux and Visual studio on Windows.

    You could use either tool to generate the project files for both platforms.

    However, the other interesting step is
    - detecting whether libsdl is actually installed on the host platform.
    - detecting if the right version is installed.
    - detecting where it is installed (if not in a standard place).
    - downloading and installing if it is missing.

    The last point is a real minefield. You don't want to have anything which might mess up a user's carefully crafted custom configuration with some badly written auto-install.

    The safe thing to do is simply report something like "I couldn't find libsdl.x in /foo or /bar".
    Then give some instructions on
    - where to get libsdl.x and install it in a standard place.
    - how to change the makefile to either use version libsdl.y, or look in /baz.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Quote Originally Posted by Salem View Post
    The make system is only one part of the portability problem.

    [...]

    - detecting whether libsdl is actually installed on the host platform.
    - detecting if the right version is installed.
    - detecting where it is installed (if not in a standard place).
    - downloading and installing if it is missing.
    Perhaps this reveals my true nature as a commercial software developer, but to me none of that seems like the developer's responsibility -- if you're going to the trouble of compiling something from source, you ought to have the knowledge necessary to deal with the above points. An autoconfiguration system that does all of that so the builder doesn't have to think about it is crazy overkill, but this is only my opinion.

    However, you should at least provide a list of what the dependencies are, what versions are necessary, and where to download the dependencies. Anything beyond that is just icing.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by brewbuck View Post
    However, you should at least provide a list of what the dependencies are, what versions are necessary, and where to download the dependencies. Anything beyond that is just icing.
    Well... When I'm downloading some software package that lists in its dependencies another package - I'd like to have a minimum readme that explains what environment vars should be set so the downloaded package will find its dependencies installed on my computer.

    Also - if it could be linked to static or dynamic version of the package, as well as release or debug version of it - It would be useful to know how to choose this settings.

    So just telling me that (for example) curl is depending on openssl and leaving the rest to me to investigate is really counterproductive.
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  5. #5
    Registered User
    Join Date
    Jun 2013
    Posts
    66
    When I'm downloading some software package that lists in its dependencies another package - I'd like to have a minimum readme that explains what environment vars should be set so the downloaded package will find its dependencies installed on my computer.
    Granted that developers of the package could be making an unfair assumption, if they only say that ABC depends on XYZ, you should simply be able to install XYZ on the system for ABC to build properly. If not, ABC should log the errors such that ABC can be configured properly. However, open source applications are notorious for being expert-friendly, which means you need at least power user knowledge to set up an open source application if it is not "install and run" like you'd expect from Windows applications.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing writing code to reading code
    By binks in forum C Programming
    Replies: 8
    Last Post: 06-12-2012, 09:41 AM
  2. Is there a way to make the following code portable?
    By manasij7479 in forum Linux Programming
    Replies: 3
    Last Post: 07-03-2011, 02:08 AM
  3. Replies: 6
    Last Post: 05-29-2011, 08:27 PM
  4. writing good code is like writing an artistic expression
    By renzokuken01 in forum C Programming
    Replies: 5
    Last Post: 02-03-2011, 08:48 PM
  5. Replies: 6
    Last Post: 01-03-2003, 05:40 PM