KnowledgeBase Archive

An Archive of Early Microsoft KnowledgeBase Articles

View on GitHub

Q123668: PRB: LNK4022 & LNK4006 Warnings When Build PowerStation 32 DLL

Article: Q123668
Product(s): Microsoft Fortran Compiler
Version(s): 1.0,4.0
Operating System(s): 
Keyword(s): kbcode kbFortranPS kbLangFortran
Last Modified: 05-NOV-1999

-------------------------------------------------------------------------------
The information in this article applies to:

- Microsoft Fortran Powerstation 32 for Windows NT, versions 1.0, 4.0 
-------------------------------------------------------------------------------

SYMPTOMS
========

The following errors are generated when building a DLL using a module definition
(.DEF) file that does not use the fully decorated name of a function named
testing:

  warning LNK4022: cannot find unique match for symbol "TESTING"
  warning LNK4006: _TESTING already defined in test.obj; second definition
  ignored
  warning LNK4006: _TESTING@4 already defined in test.obj; second definition
  ignored
  LINK : error LNK1141: failure during build of exports file

RESOLUTION
==========

Use the fully decorated name in the EXPORTS section of the DEF file or the LINK
command line.

MORE INFORMATION
================

There may be times when it is desirable not to modify the Fortran source code to
add the DLLEXPORT attribute to a function. For example, you might want to
maintain a common code base for several computer platforms. In this case, the
exports must be identified in the EXPORTS section of a .DEF file or the LINK
command line. In either case, if the name specified is not the fully decorated
name, the errors described above will be generated by the linker.

Steps to Reproduce Problem
--------------------------

1. Use the sample code listed at the end of this article and this definitions
  file:

  library test
  EXPORTS TESTING

2. Use the following LINK command to generate the error messages:

  link test.obj /dll /def:test.def msfrt.lib msvcrt.lib

NOTE: The second LNK4006 error generated by the linker gives the correct fully
decorated name "_TESTING@4". The @4 in the name indicates the number of bytes in
the function parameters.

Example Resolution
------------------

To successfully link and produce a DLL, include the fully decorated name in the
.DEF file:

  library test
  EXPORTS _TESTING@4

or in the EXPORT LINK option:

  link test.obj /dll /export:_TESTING@4 msfrt.lib msvcrt.lib

Sample Code
-----------

  C Compile options needed: none
          subroutine testing(i)
          integer i
          i = i*2
          end

Additional query words: 1.00 4.00

======================================================================
Keywords          : kbcode kbFortranPS kbLangFortran 
Technology        : kbAudDeveloper kbFortranSearch kbZNotKeyword2 kbFORTRANPower32100NT kbFORTRANPower32400NT
Version           : :1.0,4.0

=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1986-2002.