在Visual Studio 2008中编译libpng时出错

时间:2012-10-03 07:26:09

标签: c windows-mobile libpng

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

为此,我从模板“c ++ SmartDevice类库”创建了一个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中不会导致相同的编译器错误。

1 个答案:

答案 0 :(得分:0)

编译成.lib成功完成。

原因是不合理的。