Can I define an environment variable and use it in conditional compilation?

前端 未结 1 1744
心在旅途
心在旅途 2021-01-17 18:11

I know that I can do this in a *.h file:

#ifdef _DEBUG
#pragma comment(lib, \"libtiffd.lib\")
#else
#pragma comment(lib, \"libtiff.lib\")
#endif
相关标签:
1条回答
  • My test: Create environment variable MY_VERSION = V2_4_6. Start VS, in project properties, C++, Preprocessor, Preprocessor Definitions, add $(MY_VERSION). This program:

    #ifdef V2_4_6
        cout << "OK" << endl;
    #else
        cout << "??" << endl;
    #endif
    

    prints "OK". Exit Visual Studio, change MY_VERSION value to another value or remove it. Start VS, rebuild the program. Now it prints "??".

    Note that after changing the variable value it is neccesary to restart Visual Studio (since environment variables are not refreshed dynamically), and make Rebuild All.

    0 讨论(0)
提交回复
热议问题