Nav
Nav

Reputation: 20648

How to display a #defined constant during build, in Visual Studio 2010?

I've seen this, but none of the answers worked for VS2010. The constant's (or should I call it variable?) numerical value didn't get displayed

This line of code #if OGRE_PLATFORM == OGRE_PLATFORM_LINUX is turning out to be true when I'm actually programming in windows. I need to see the value of OGRE_PLATFORM_WIN32 and OGRE_PLATFORM_LINUX during the build process itself. Could you help with how to go about it?

Upvotes: 1

Views: 2752

Answers (2)

parkovski
parkovski

Reputation: 1513

First, check the preprocessor defines in project options - active configuration and all configurations, and make sure the right things are defined.

If you are still having problems, try substituting this for your main method:

#include <iostream>

int main()
{
    #ifdef OGRE_PLATFORM_LINUX
    std::cout << "OGRE_PLATFORM_LINUX = " << OGRE_PLATFORM_LINUX << "\n";
    #else
    std::cout << "OGRE_PLATFORM_LINUX not defined.\n";
    #endif

    #ifdef OGRE_PLATFORM_WIN32
    std::cout << "OGRE_PLATFORM_WIN32 = " << OGRE_PLATFORM_WIN32 << "\n";
    #else
    std::cout << "OGRE_PLATFORM_WIN32 not defined.\n";
    #endif

    #ifdef OGRE_PLATFORM
    std::cout << "OGRE_PLATFORM = " << OGRE_PLATFORM << "\n";
    #else
    std::cout << "OGRE_PLATFORM not defined.\n";
    #endif

    return 0;
}

Also, did you create the project, was it created by some type of pre-make (CMake, automake, etc) system, did you download it from somewhere? If you didn't create it, somebody could have ported over some Linux code without checking their preprocessor options.

Upvotes: 0

Alok Save
Alok Save

Reputation: 206498

You can check the preprocessor output using:

  • /E - preprocess to stdout or
  • /P - preprocess to file or
  • /EP - preprocess to stdout without #line directives

options in visual studio

Upvotes: 2

Related Questions