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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:55:46+00:00 2026-05-20T19:55:46+00:00

I have a static library that is used in production code and test code.

  • 0

I have a static library that is used in production code and test code. I want to be able to inject test data only if I am building the test .exe. I would like to do this using preprocessor #defines, rather than MSVS configurations (e.g., Debug vs. Release) because I am testing performance. Debug builds turn off optimization, which is great during debugging but not so great when I want to test performance.

As an example, say I have Foo.lib, Production.exe, and Test.exe projects in MSVS. Production.exe and Test.exe both link Foo.lib. I would like Production.exe and Test.exe to rebuild Foo.lib with their respective preprocessor definitions, so the code in Foo.lib will conditionally compile based on which executable it is targeted for.

I’m open to other solutions, and I hope I stated my problem clearly. First post on stack overflow.

  • 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-20T19:55:47+00:00Added an answer on May 20, 2026 at 7:55 pm

    You’ll need to set up multiple solution configurations to support each of the scenarios you desire. First we’ll add a new Test configuration to the static library, and create an accompanying Test solution configuration:

    • In Solution Explorer in Visual Studio, right click on the top-level solution node.
    • Click Configuration Manager…
    • Find your C/C++ static library project in the project list. Click the Configuration cell for that project. It will turn into a drop-down. Pick New.. from that drop-down.
      • Enter in a name for a new project configuration. Call it whatever you like. In these steps, I’ll call it Test.
      • For the Copy settings from: field, select Release, since you want a test configuration that does have optimization enabled.
      • Leave the Create new solution configurations checkbox checked.
      • Click OK

    Now you can modify your static library’s new Test configuration with your desired #defines:

    • Find your C/C++ project in Solution Explorer. Right-click on it and select Properties…
    • Select your new Test configuration from the Configuration drop-down at the top-right.
    • In the left-hand pane, select Configuration Properties | C/C++ | Preprocessor
    • On the right, add your desired #defines to the list of Preprocessor Definitions

    …now, you want to set your builds up so that you have a build configuration that builds Test.exe with the static library’s Test configuration, and the Release.exe with the library’s Release configuration. Go back to the Configuration Manager (as we did in the first two steps above):

    1. Set up your build configuration for Release.exe:

      • In the top-left drop down, select Release as the Active solution configuration:
      • For your Release.exe project, select its Release configuration, and make sure Build is checked
      • For your Test.exe project, make sure Build is unchecked.
      • For the static library, select its Release configuration, and make sure Build is checked
    2. Set up your build configuration for Test.exe:

      • In the top-left drop down, select Test as the Active solution configuration:
      • For your Release.exe project, make sure Build is unchecked.
      • For your Test.exe project, select its Release configuration (I assume that’s what you want), and make sure Build is checked
      • For the static library, select its Test configuration, and make sure Build is checked

    Now, when you change your solution to Test or Release configuration, I’d expect you to have the build behavior you desire for each.

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

Sidebar

Related Questions

I have a static library that I am building in C++. I have separated
I have a static library, Foo, that is used by a shared library, Bar.
I have a static library (let's call it S) that uses a category (NSData+Base64
I was given an static library (.a extension file) that I have to use
I have a Visual Studio 2008 C++ project that outputs a static library and
I have some code shared among multiple projects in a static library. Even with
I have some code that creates a batch using the pyglet library. The whole
I build a static library that uses Objective-C++. When it is used in a
I have a static S.lib that is used by my D.dll. I'm trying to
I have created one static library in iPhone sdk, and I am worried that

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.