Symbian
Symbian OS Library

FAQ-0774 What causes "warning LNK4089: all references to "XXX.DLL" discarded by /OPT:REF"?

[Index][spacer] [Previous] [Next]



 

Classification: C++ Category: Development
Created: 01/29/2002 Modified: 09/11/2002
Number: FAQ-0774
Platform: Not Applicable

Question:
When I build for WINS I get a link warning about all references to a DLL being "discarded by /OPT:REF". How can I remove this warning? I've tried removing the library from the MMP file but that causes a fatal error...

Answer:
The MSDN description of LNK4089 says:
      The linker discarded all packaged functions that referenced exports in dynamic-link library.
      As a result,
      dynamic-link library and its import library are unneeded.
      What this means is that the code which uses functions from the given DLL is not itself called from anywhere else in your program. For example:

      void MyClass::Adjust(TInt aFactor)
      {
      __ASSERT_DEBUG(ConsistencyCheck()==KErrNone, Panic(EInconsistentMyClass));
      // make adjustment
      }

      TInt MyClass::ConsistencyCheck()
      {
      // Check which uses function from XXX.DLL
      if (XXX_check(iMember1, iMember2) != KErrNone)
      return KErrGeneral;
      // more checking
      return KErrNone;
      }

      This code would fail to compile unless linked against XXX.lib because it refers to XXX_check(), but in UREL builds the ASSERT_DEBUG macro does nothing and so there is no call to MyClass:ConsistencyCheck(). The Developer Studio linker detects this and removes the code associated with that function, which in turn means that there is no longer any call to XXX.DLL, which causes the linker to emit the warning.

      The fix in this case is to surround the whole of MyClass::ConsistencyCheck with #ifdef _DEBUG ... #endif, and then specify XXX.LIB as a DEBUGLIBRARY in the MMP file.

      In general, to find out what's going on you probably need to remove the XXX.LIB file from the MMP file and rebuild to see what the link errors are. This will tell you which functions are referring to the DLL, and you can then work backwards to find out why those functions are unreachable in the UREL build.

      NB. The GCC linker does not attempt to remove dead code in this way, so it's only the WINS build which will show this kind of warning.