Opened 19 years ago

Closed 13 years ago

#747 closed defect (invalid)

Incorrect export/import directives for GDAL libraries

Reported by: mbrudka@… Owned by: warmerdam
Priority: high Milestone:
Component: default Version: unspecified
Severity: major Keywords:
Cc:

Description (last modified by Even Rouault)

Currently, GDAL libraries are exported using the following macros (cpl_port.h)
#ifndef CPL_DLL
#if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
#  define CPL_DLL     __declspec(dllexport)
#else
#  define CPL_DLL
#endif
#endif
Obviously, this incorrected, because it does not import symbols when *using* GDAL libraries eg. 
see MSDN help. I propose to use the same schema as in ACE multiplatform library:

// -*- C++ -*-
// $Id$
// Definition for Win32 Export directives.
// This file is generated automatically by generate_export_file.pl CPL
// and customized by Marek Brudka <mbrudka@aster.pl> for GDAL
// ------------------------------
#ifndef CPL_DLL_H
#define CPL_DLL_H
/* 
CPL_HAS_DLL  switches between shared and static libraries setup (old CPL_DISABLE_DLL )
  1 build and use shared library, 
  0 built and use static library

CPL_BUILD_DLL - considered only for shared libraries setup, 
    ( MSVC for new shared library project cpl generates CPL_EXPORT macro)
  defined - export symbols, as shared library is built now
  undefined - import symbols from shared library into application
*/
#if !defined (CPL_HAS_DLL)
#  define CPL_HAS_DLL 1
#endif /* ! CPL_HAS_DLL */

#if defined (CPL_HAS_DLL) && (CPL_HAS_DLL == 1) && defined(_MSC_VER)
#  if defined (CPL_BUILD_DLL)
#    define CPL_DLL __declspec(dllexport)
#  else /* CPL_BUILD_DLL */
#    define CPL_DLL __declspec(dllimport)
#  endif /* CPL_BUILD_DLL */
#else /* CPL_HAS_DLL == 1 */
#  define CPL_DLL
#endif /* CPL_HAS_DLL == 1 */

#endif /* CPL_DLL_H */

// End of auto generated file.
When building shared library GDAL one has to enable shared library build, namely define 
CPL_HAS_DLL=1, and define CPL_BUILD_DLL. When building an application using shared library 
GDAL one must not define CPL_BUILD_DLL to import symbols from gdal.dll.

Change History (2)

comment:1 by mbrudka@…, 19 years ago

To see the result of the one may create a shared library depending on GDAL and the application 
which links with this library and GDAL.

comment:2 by Even Rouault, 13 years ago

Description: modified (diff)
Resolution: invalid
Status: newclosed

Apparently people manage to use GDAL on windows without that... So closing.

Note: See TracTickets for help on using tickets.