locked
Looking for compiler macro to skip #pragma comment(lib,"filename.lib") RRS feed

  • Question

  • This is like a chicken and egg issue and I am trying to avoid having to create another compiler macro.

    I have a dll,  example,  wcdns.cpp with a wcdns.h interface header structures and function prototype statements and an import lib statement using the comment lib pragma.

    The problem is when compiling wcdns.cpp the first time, i.e. after a clean, the wcdns.lib is missing so you get a link "missing wcdns.lib" missing.    One way to resolve this is to set a preprocessor macro for the dll project:

          "MAKE_WCDNS"

    and then wrap this around the #pragma in wcdns.h

    #ifndef MAKE_WCDNS
    #  ifdef _WIN64
    #    pragma comment(lib,"wcdns64.lib")
    #  else
    #    pragma comment(lib,"wcdns.lib")
    #  endif
    #endif


    Now other projects can use the wcdns.h and the main wcdns.cpp compile/link won't barf.

    My question, I have to repeat this for multiple DLLs,  is there a built in macro that is set that will signal the DLL is being created?   Of course, I can add the wcdns.lib to all the other projects link setup, but I have to many project configurations, I just want to deal with the main wcdns.cpp and not worry about other projects. 

    Is there another technique?

    Thanks


    Hector Santos, CTO Santronics Software, Inc. http://www.santronics.com

    Sunday, April 21, 2019 8:44 PM

Answers

  • By default when VS2015 creates a Win32 Dll project it includes a preprocessor definition such as PROJECTNAME_EXPORTS in the compiler's property page for the preprocessor.  Perhaps you could use that in your header to control the #pragma for the import lib.
    • Marked as answer by hector santos Monday, April 22, 2019 12:42 AM
    Sunday, April 21, 2019 9:55 PM

All replies

  • By default when VS2015 creates a Win32 Dll project it includes a preprocessor definition such as PROJECTNAME_EXPORTS in the compiler's property page for the preprocessor.  Perhaps you could use that in your header to control the #pragma for the import lib.
    • Marked as answer by hector santos Monday, April 22, 2019 12:42 AM
    Sunday, April 21, 2019 9:55 PM
  • So there were suppose to be a WCDNS_EXPORTS already existing? Must of been removed.   Ok, I'll use this technique. Thanks

    Hector Santos, CTO Santronics Software, Inc. http://www.santronics.com

    Monday, April 22, 2019 12:42 AM