l Windows Mobile 6.1 で動作するプログラムで libpng を使用しようとしています。
そのために、テンプレート「c++ SmartDevice Class library」からc++プロジェクトを作成し、ガイドとして提供されているビジュアルスタジオプロジェクトを使用して、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 にコンパイルしても、同じコンパイラ エラーは発生しません。