Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8585041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:57:48+00:00 2026-06-11T21:57:48+00:00

In my GNU/Linux environment, my software would have all of its graphical resources installed

  • 0

In my GNU/Linux environment, my software would have all of its graphical resources installed under /usr/share/pixmaps. In Wintendo everything would go into C:\Program files\myappname. In a different OS, somewhere else.

What are the most common ways, conventions, good practices so I can abstract my way to refer to the files I open in my code in a paths/installation/build independant way? Basically a portable way to refer to resources paths.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T21:57:49+00:00Added an answer on June 11, 2026 at 9:57 pm

    Create a preprocessor ifelse chain of OS defines that #defines a function name mapped to a real function call that retrieves the correct path:

    #if _WIN32
    #define GetResourcesFolderString GetResourcesFolderStringW
    #elif ((macintosh) || (Macintosh) || (__APPLE__ & __MACH__))
    #define GetResourcesFolderString GetResourcesFolderStringM
    #elif __gnu_linux__
    #define GetResourcesFolderString GetResourcesFolderStringU
    //...and so on
    #endif
    
    //...Later...
    
    std::string GetResourcesFolderStringW() {
        return "C:/Program files/myappname/"
    }
    std::string GetResourcesFolderStringM() {
        return "Mac folder path here";
    }
    std::string GetResourcesFolderStringU() {
        return "/usr/share/pixmaps/";
    }
    

    This way you only call one function, and depending on your build target the correct function is called with no change in code.

    Hard-coding the paths is generally not a good idea and is used here for illustration purposes only. You should probably set up a configuration file or similar to allow for individual systems to have separate install paths and still be able to find the resources.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of C++ code (compiled with g++ under a GNU/Linux environment)
In a Unix or GNU scripting environment (e.g. a Linux distro, Cygwin, OSX), what
In a Unix or GNU scripting environment (e.g. a Linux distro, Cygwin, OSX), what
I'm quite fond of using GNU getopt , when programming under Linux . I
The GNU/Linux version of cp has a nice --update flag: -u, --update copy only
I'm working on a custom version of a GNU/Linux live distribution. I need to
I'm working on a C++ project on GNU/Linux and I'm looking for a way
I'm writing some small bash scripts for copiyng certain files/directories in GNU/Linux and Solaris.
I want to build a shared library. GNU/Linux is the development and target platform.
I am using PostgreSQL 9.1.3 (PostgreSQL 9.1.3 on x86_64-pc-linux-gnu, compiled by gcc-4.6.real (Ubuntu/Linaro 4.6.1-9ubuntu3)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.