1

I tried to use a library on visual studio in different ways by modify its macros on preprocessor directives. However a logic block inside an #if directive is shown to me inactive as it was comment. Here is the code:

  #if defined EBML_DLL
    #if defined EBML_DLL_EXPORT
      #define EBML_DLL_API __declspec(dllexport)
    #else // EBML_DLL_EXPORT
      #define EBML_DLL_API __declspec(dllimport)
    #endif // EBML_DLL_EXPORT
  #else // EBML_DLL
    #define EBML_DLL_API
  #endif // EBML_DLL

The problems is that visual studio shows the code within if ebml_dll block inactive (as commented). As result, the dll doesn't show the functions in the object browser of VS.

A Hint: if a backslash is added at the end of #if defined EBML_DLL's line, it active the else block only.

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129

1 Answers1

1

There was a bug in older versions of VS about this, but it was just a display issue. VS was not reading the defines correctly (in your case EBML_DLL, etc).

It could also be that the constants you are using in your preprocessor statements are not correct and the are missing characters (usually the ones the compiler uses have underscores at the beginning and end)

To really know for sure which one it is, you can add a random string inside the branch the preprocessor is expected to take and see if the code compiles.

#if defined EBML_DLL
 this_should_not_compile //you should get an error on this line
#endif 

Hope this helps...

Pandrei
  • 4,843
  • 3
  • 27
  • 44
  • thank for the replay. Acording to your anwser the cause is that preprocessor don't recognize the stament within the if else block. thats razonable because EBML_DLL_EXPORT, EBML_DLL etc.. are all define using -D option for the compiler. – israel.sincro Mar 02 '15 at 13:34
  • no, the preprocessor, or VS display part, has a problem evaluating if the constants used in the preprocessor directives are defined or not. If you say you pass them using the -D option in you toolchain, than there is no way VS can know about them until compile time. I think this was fixed in one of the newer release of VS. – Pandrei Mar 02 '15 at 13:38
  • thank for the replay. I test your code seem to be a display bug, It create the library, however it dont show the functions added on the objetc browser. and that cause an funtion cant be found error once i try to use that function. However now the error seems nat be a preprocessor problem. thanks again – israel.sincro Mar 02 '15 at 13:42
  • i ll like to.. but it saids i need 15 reputation. But thanks for the help – israel.sincro Mar 02 '15 at 17:30
  • you still have the favorite answer flag...anyway all the best! – Pandrei Mar 03 '15 at 09:40