FIX: L2029 Error Calling ODBC Functions from ODBC SDK

ID: q108522


The information in this article applies to:
  • Microsoft C/C++ for MS-DOS, version 7.0
  • Microsoft Visual C++ for Windows, 16-bit edition, version 1.0


SYMPTOMS

When building an application using the ODBC Software Development Kit (SDK), linker error L2029 "unresolved external" may occur on calls made to ODBC functions.


CAUSE

Several header files included with the ODBC SDK are missing extern "C" statements, which are needed to make them compatible with a C++ compiler. The functions residing in the ODBC libraries do not have decorated names, and therefore the extern "C" statement is necessary if you are calling the functions from an application written in C++.

The following header files are affected by this problem:


   SQL.H
   SQLEXT.H
   ODBCINST.H
   ODBCVER.H 


RESOLUTION

There are two ways to handle this problem:

  • Modify the ODBC header files to include the missing extern "C" statements. For example:
    
          #ifdef __cplusplus
          extern "C" {   /* Assume C declarations for C++ */ 
          #endif
              .
              .  // The body of the header file goes here.
              .
          #ifdef __cplusplus
          }
          #endif 
    This is the preferred way of handling this situation. This solution will correct the problem permanently.


  • -or-

  • Wrap the include statements in your own program where these header files are brought in. For example:
    
          extern "C" {
          #include <SQL.H>
          #include <SQLEXT.H>
          ....
          } 
    This method of working around the problem should be used on a temporary basis only. This method will allow you to link successfully, but each time one of these header files is included in your program, it will need to be wrapped by an extern "C" statement.



STATUS

Microsoft has confirmed this to be a problem in the products listed at the beginning of this article. The problem was corrected in Visual C++ for Windows version 1.5 by including new versions of the four header files listed above.

Additional query words: 1.00 1.50 7.00 8.00 8.00c

Keywords : kb16bitonly kbCompiler kbCPPonly kbVC
Version : 7.00 | 1.00
Platform : MS-DOS WINDOWS
Issue type :


Last Reviewed: July 31, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.