0

l我正在尝试在程序中使用libpng,在Windows Mobile 6.1上工作。

为此,我从模板“c++ SmartDevice Class library”创建了一个 c++ 项目,并使用那里提供的 Visual Studio 项目作为指南,从 libpng 添加了适当的 c 源文件,并将 libpng 源的目录添加到源搜索目录。

但是,当我尝试编译时,出现以下错误:

error C2054: expected '(' to follow 'PNG_DLL_EXPORT'    <path>\lib\lpng1512\png.h   991

换句话说,首先 PNG_DLL_EXPORT 会导致错误,然后在 png.h 的每一行中都会出现错误。

原因是什么?这应该如何解决?这是一个已知问题吗?

更新:那里使用的确切宏是 PNG_EXPORT。它在 pngconf.h 中定义为:

#define PNG_EXPORT(ordinal, type, name, args)\
   PNG_EXPORTA(ordinal, type, name, args, PNG_EMPTY)

因此,使用的宏定义为:

/* ANSI-C (C90) does not permit a macro to be invoked with an empty argument,
 * so make something non-empty to satisfy the requirement:
 */
#define PNG_EMPTY /*empty list*/

/* The ordinal value is only relevant when preprocessing png.h for symbol
* table entries, so we discard it here.  See the .dfn files in the
* scripts directory.
*/
#ifndef PNG_EXPORTA

#  define PNG_EXPORTA(ordinal, type, name, args, attributes)\
      PNG_FUNCTION(PNG_EXPORT_TYPE(type),(PNGAPI name),PNGARG(args), \
        extern attributes)
#endif

在兔子洞下面,有:

/* In 1.5.2 the definition of PNG_FUNCTION has been changed to always treat
 * 'attributes' as a storage class - the attributes go at the start of the
 * function definition, and attributes are always appended regardless of the
 * compiler.  This considerably simplifies these macros but may cause problems
 * if any compilers both need function attributes and fail to handle them as
 * a storage class (this is unlikely.)
 */
#ifndef PNG_FUNCTION
#  define PNG_FUNCTION(type, name, args, attributes) attributes type name args
#endif

#ifndef PNG_EXPORT_TYPE
#  define PNG_EXPORT_TYPE(type) PNG_IMPEXP type
#endif

再往下:

#  if (defined(_MSC_VER) && _MSC_VER < 800) ||\
      (defined(__BORLANDC__) && __BORLANDC__ < 0x500)
    /* older Borland and MSC
     * compilers used '__export' and required this to be after
     * the type.
     */
#    ifndef PNG_EXPORT_TYPE
#      define PNG_EXPORT_TYPE(type) type PNG_IMPEXP
#    endif
#    define PNG_DLL_EXPORT __export
#  else /* newer compiler */
#    define PNG_DLL_EXPORT __declspec(dllexport)
#    ifndef PNG_DLL_IMPORT
#      define PNG_DLL_IMPORT __declspec(dllimport)
#    endif
#  endif /* compiler */

在其他文件中,pngpriv.h,PNG_DLL_EXPORT 最终被使用:

/* See pngconf.h for more details: the builder of the library may set this on
 * the command line to the right thing for the specific compilation system or it
 * may be automagically set above (at present we know of no system where it does
 * need to be set on the command line.)
 *
 * PNG_IMPEXP must be set here when building the library to prevent pngconf.h
 * setting it to the "import" setting for a DLL build.
 */
#ifndef PNG_IMPEXP
#  ifdef PNG_BUILD_DLL
#     define PNG_IMPEXP PNG_DLL_EXPORT
#  else
      /* Not building a DLL, or the DLL doesn't require specific export
       * definitions.
       */
#     define PNG_IMPEXP
#  endif
#endif

Update2:这个问题是特定于编译成 dll 的。编译成 lib 不会导致相同的编译器错误。

4

1 回答 1

0

编译成 .lib 成功完成。

不过,原因尚不清楚。

于 2012-10-10T11:32:41.163 回答