Visual Studio 2010 - trying to conditionally compile static library based on target .exe?

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): 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 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.

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): 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 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.

Thanks, Andrew. Your response answers my question. I'm still going to look into the seemingly better solution to my problem posted by Hans.

– Bill Mar 17 at 18:35.

This sounds very wrong, test data doesn't belong in a .lib. And testing code that's built in another way than it is used on the target machine is not a true test. VS keeps you out of trouble here, this just isn't possible.

You have to use another configuration to change the way the . Lib gets built. Have the test app supply the test data to the .

Lib instead. Just as the real app supplies it with real data after you deployed it.

Thanks for the response. This particular application is using the microphone as data input. I'll look into stubbing out the microphone data acquisition.

– Bill Mar 17 at 18:29 1 Ah, when I read "static library...used in test code" , I was thinking "release build of a static library, but with assertions enabled in the static library sources. " Such a setup used to be relatively common. Hans feedback concerning the original questions premise is very good.

– Andrew Brown Mar 17 at 18:43.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions