locked
Want to fix a linker warning

    Question

  • Small link warning problem

    I've taken the Simple3DGameXaml sample's Audio files (Audio/MediaReader/SoundEffect) as a starting point to make a sound library in an existing static library in my project.

    I needed to add xaudio2.lib, mfreadwrite.lib, mfuuid.lib, and mfplat.lib to my project as would be expected.

    I can't seem to figure out how to get rid of the following warnings:


    1>xaudio2.lib(XAudio2_8.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in d3d11.lib(d3d11.dll); second definition ignored

    1>xaudio2.lib(XAudio2_8.dll) : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library

    1>mfreadwrite.lib(MFReadWrite.dll) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in d3d11.lib(d3d11.dll); second definition ignored

    1>mfreadwrite.lib(MFReadWrite.dll) : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library

    1>mfplat.lib(MFPlat.DLL) : warning LNK4006: __NULL_IMPORT_DESCRIPTOR already defined in d3d11.lib(d3d11.dll); second definition ignored

    1>mfplat.lib(MFPlat.DLL) : warning LNK4221: This object file does not define any previously undefined public symbols, so it will not be used by any link operation that consumes this library



    I understand this is hurting nothing, but the warnings in my listing always cause me to focus on the messages, and I would like to get rid of them.  I know I can just use /IGNORE, but these are warning messages I would rather keep around, and just fix whatever problem I've got.

    I could not find anything (either in macros or the project files) that inhibits these warnings in the sample game.  Any ideas would be appreciated.


    Jim Tomasko

    Monday, November 05, 2012 9:33 PM

Answers

  • You are linking d3d11.lib more than once. I suspect your static library is linking it, as well as your target application.

    You should never link other static libraries to your static library. All static library linking should be done by the target application ONLY.
    • Marked as answer by James Tomasko Thursday, November 22, 2012 10:36 PM
    Monday, November 12, 2012 8:12 AM

All replies

  • You are linking d3d11.lib more than once. I suspect your static library is linking it, as well as your target application.

    You should never link other static libraries to your static library. All static library linking should be done by the target application ONLY.
    • Marked as answer by James Tomasko Thursday, November 22, 2012 10:36 PM
    Monday, November 12, 2012 8:12 AM
  • Why not?   I'd like my static library to carry its dependencies with it, wherever it goes.
    Sunday, August 17, 2014 9:40 AM
  • Linking Windows SDK provided .libs into your static library is highly problematic.

    A better solution to your concern is to use #pragma comment(lib,"d3d11.lib") in the 'public' header for your static library. This causes client applications to pick up the dependacy (unless "NODEAULTLIB" is enabled of course).

    Sunday, August 17, 2014 7:00 PM
  • @Chuck - Thanks for your prompt reply, still not sure I understand.

    Is linking windows sdk provided .libs considered dangerous just in a scenario where I'm writing static libraries to be used by another party? In my scenario I'm using static libs just to reuse code across different in-house products.  Is this considered safe?

    Sunday, August 17, 2014 9:13 PM