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 6329279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:37:43+00:00 2026-05-24T17:37:43+00:00

I have a configuration class that I would like to use for a variety

  • 0

I have a configuration class that I would like to use for a variety of builds. The class itself changes between builds, but the class name remains the same, as does the header file name.

The separate versions of this class are held in separate subfolders.

ex.

  • main/config.h

  • main/config.cpp

  • secondary/config.h

  • secondary/config.cpp

Is there a good way to, through a compile-time flag or command line option, have the build determine which header/cpp to use? I have quite a few configurations already, and expect to have many more in the future. I would like to avoid a long list of #ifdef/#elif/#elif/etc..

edit: I would like to avoid having separate builds, and would like to avoid using #defines throughout the code. I’m sorry if I didn’t make that clear before! >_<

  • 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-05-24T17:37:46+00:00Added an answer on May 24, 2026 at 5:37 pm

    Depending on what build system you are using you would create a variable that points to the main or secondary path. This variable is then used to append to the INCLUDE path so all of your sources can just #include "config.h" when they need access to config. In your Makefile (or equivalent) you will need to add the $CONFIGPATH/config.cpp to your sources to build.

    MSBuild

    Update source file paths:

    <ItemGroup>
        <ClCompile Include="main.cpp" />
        <ClCompile Include="$(ConfigToUse)/config.cpp" />
    </ItemGroup>
    <ItemGroup>
         <ClInclude Include="$(ConfigToUse)/config.h" />
    </ItemGroup>
    

    And the include path:

    <PropertyGroup>
        <ConfigurationType>Application</ConfigurationType>
        <ShowAllFiles>false</ShowAllFiles>
        <IncludePath>...;$(ConfigToUse);</IncludePath>
    </PropertyGroup>
    

    Then call msbuild build.xml /p:ConfigToUse=PathToConfig

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

Sidebar

Related Questions

Let's say I have a class that requires configuration, dependency injection etc. public class
I have the following log4j.xml configuration: <log4j:configuration> <appender name = CONSOLE class = org.apache.log4j.ConsoleAppender>
I have a class like: class Configuration def self.files @@files ||= Array.new end end
I have a web project that uses a custom configuration class to store app
I've encountered some problems with MongoID. I have three models: require 'mongoid' class Configuration
i have class named Group i tried to test configuration: var cfg = new
I have a class on which I want to allow several (~20+) configuration options.
So I have this code inside my lib/ folder: class GlobalConfig::SetHelper def self.yes_no_input(configuration) value
I have configuration entity in my .NET CF application and I want to use
Well, I have a configuration object that contains the settings for various kinds of

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.