-
April 7th, 2010, 02:07 AM
#1
Facing problems with #ifdef directives in VS 2008
Hello All,
1. recently i have upraded my application from VS 2005 to VS 2008.
2. I have a preprocessor directives defined in ProjectProperties | C/C++ | PreProcessor Definitions.
3. I used this PreProcessor definition in a cpp file via #ifdef.
/CODE
#ifdef RIV
....
...
#endif
CODE/
4. Observation is that, when i build by application in VS 2008 , code put in the #ifdef block is not getting executed at runtime. Whereas there was no problem with this piece of code when i build my application in VS 2005.
5. pl. advice to resolve this issue.
-
April 7th, 2010, 02:15 AM
#2
Re: Facing problems with #ifdef directives in VS 2008
Hi,
where did you define the "RIV"?
Is there a
statement anywhere in your code or is this defined elsewhere?
Maybe it was predefined in your project's settings?
-
April 7th, 2010, 02:34 AM
#3
Re: Facing problems with #ifdef directives in VS 2008
please refer to #2 of my query. i have defined RIV in ProjectProperties.
-
April 7th, 2010, 04:02 AM
#4
Re: Facing problems with #ifdef directives in VS 2008
Hi,
Well, it *should* work. Just double-checked on VS2008 here.
Adding this:
Code:
#ifdef RIV
fall over
#endif
is seen by the compiler if I add RIV to the preprocessor definitions in the project properties.
I suggest a clean and rebuild, then debug it by adding a #define RIV to your code to see what happens.
-
April 7th, 2010, 06:10 AM
#5
Re: Facing problems with #ifdef directives in VS 2008
hi alanjhd08,
We too tried the option
[CODE]
#define RIV
#ifdef RIV
...
#endif
[CODE]
and it worked. But it our case is that this PreProcessor directive needs to be put via ProjectProperties. Because, this file is common for two projects, and one project needs a segment of code specific to it; hence the {#ifdef RIV ... #endif} block.
-
April 7th, 2010, 06:16 AM
#6
Re: Facing problems with #ifdef directives in VS 2008
Hi, so you confirmed the problem is only when defining it via the Preprocessor.
When you go into project properties, and look at C++ "Command Line" for the configuration you are building, do you see /D "RIV" under All options: ?
-
April 7th, 2010, 06:31 AM
#7
Re: Facing problems with #ifdef directives in VS 2008
maybe you added the RIV define only in the release build settings and not in debug (or vice versa) ?
-
April 7th, 2010, 07:49 AM
#8
Re: Facing problems with #ifdef directives in VS 2008
1. RIV is defined in both the modes.. release & debug.
2. /D "RIV" is shown in properties-> C/C++-> "Command Line".
Still #ifdef RIV block is not getting executed.
-
April 7th, 2010, 09:42 AM
#9
Re: Facing problems with #ifdef directives in VS 2008
Originally Posted by pmohod
1. RIV is defined in both the modes.. release & debug.
2. /D "RIV" is shown in properties-> C/C++-> "Command Line".
Still #ifdef RIV block is not getting executed.
So we have these scenarios:
1) Somewhere, some file has an #undef RIV before that block of code is executed.
2) You don't have /D "RIV" in the project settings or your compiling something that isn't using those settings.
3) You're observations are incorrect, and what is defined in #ifdef RIV is being executed.
4) The Visual Studio IDE has a bug, and the make program isn't picking up the project settings.
It isn't anything else. Let's look at 3).
Code:
#ifdef RIV
#pragma message ("Hello -- RIV is defined OK!")
#endif
Now, if you compile your code, the compiler will output the message
Code:
Hello -- RIV is defined OK!
in the compiler Output Window if RIV is really defined. If you do see it, then your observations are incorrect, and RIV is being defined. If you don't see it, then investigate the other possibilities.
Regards,
Paul McKenzie
-
April 8th, 2010, 01:10 AM
#10
Re: Facing problems with #ifdef directives in VS 2008
One more clarification regarding our query
1. If we add the preprocessor in the same project settings which creates the .exe, then it works
2. However, we want to add the preprocessor in a library project settings and use it into the project that creates the application .exe
Simplifying, suppose there are two projects - A and A_Lib
Project A - creates the application A.exe ----> adding the preprocessor in this project settings works fine
Project A_Lib - creates the library A_Lib.lib.
Now, if we add the preprocessor in Project A_Lib settings, and use it in Project A, then it does not execute the #ifdef block.
We have linked A_Lib with Project A (Properties --> Linker --> Input --> Additional Dependencies)
This is what we are trying to overcome.
-
April 8th, 2010, 03:50 AM
#11
Re: Facing problems with #ifdef directives in VS 2008
Hi,
I'm not sure I understand the setup, can you confirm:
The same arrangement worked fine under VS2005, only change is move to 2008.
The code which includes #ifdef RIV is in the project A_lib, and RIV is defined as a preprocessor directives in ProjectProperties | C/C++ | PreProcessor Definitions for that project.
You build the project A_lib with those settings, before linking it from project A.
Is that right? Or maybe the project A_lib isn't getting rebuilt for some reason, but you expect it to because it is defined as an additional dependency?
-
April 8th, 2010, 04:36 AM
#12
Re: Facing problems with #ifdef directives in VS 2008
Hi alanjhd08,
You interpreted all the points correctly except point #2. Let me clarify.
1. "The same arrangement worked fine under VS2005, only change is move to 2008." ----> Correct
2. The code which includes #ifdef RIV is in the project A (which creates .exe).
RIV is defined as a preprocessor directives in ProjectProperties | C/C++ | PreProcessor Definitions for project A_lib.
3. "You build the project A_lib with those settings, before linking it from project A." ----> Correct
.... We rebuilt project A_Lib explicitly before building Project A.
Can you guide us where we are going wrong?
-
April 8th, 2010, 04:55 AM
#13
Re: Facing problems with #ifdef directives in VS 2008
Hi,
Sorry, I can't think of anything.
I can't see how defining RIV for the library, but not the project that includes the code, would ever have worked, so looks like I'm misunderstanding something.
Alan
-
April 8th, 2010, 08:04 AM
#14
Re: Facing problems with #ifdef directives in VS 2008
Hi All,
Our issue has been sorted internally. Turned out we had added some libs which were not required in the settings, and they were over-riding the RIV preprocessor. Removing those unwanted lib depencies sorted the problem.
Thank you all for your efforts and help, really appreciated :-):-)
-
April 9th, 2010, 09:28 AM
#15
Re: Facing problems with #ifdef directives in VS 2008
Many thanks to the codeguru community for interacting with us and giving us relevant directions to analyse the situation.
#1 of Paul McKenzie April 7th, 2010 02:42 PM gave some thoughts to us in investigating which might be nullifying the definition of RIV PreProcessor.
If I continue to borrow the terms A.Exe, A_Lib.lib, we have put A_Lib.lib as the first library in Linker | Input | Additional Dependencies. This made "#ifdef RIV" block of code work.
Then we started Lowering the position of this A_Lib.lib until "#indef RIV" failed, thus identifying which lib in the list of dependencies is nullifying the RIV definition.
It turned out that addition of this B.lib in the list of additional dependencies is a mistake on the part of the developer. We rectified it, and thereafter things went well.
i give these details so that if someone somewhere gets into this kind of issues, and happens to read this post, he may get a skill to do the trouble shooting.
Thanks once again to the community.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|