[Gdal-dev] Incorrect export/import directives for GDAL libraries

Marek Brudka mbrudka at aster.pl
Wed Jan 19 12:29:50 EST 2005


Hi,
    I posted another bug report related with shared libraries:

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 at 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.

Best regards
MArek Brudka




More information about the Gdal-dev mailing list