【发布时间】:2011-10-30 22:38:10
【问题描述】:
我正在制作一个共享库(跨平台),但在尝试编译 Windows 版本时遇到错误:
secure_string.h(43):错误 C2059:语法错误:'type'
这是关于 SECURESTRING_API 宏的。它不会抱怨 strlcpy 和 strlcat 中的两种用法,但是当尝试将其用于 'str_from_last' 时,它会产生上述错误。 如果我删除它,它编译得很好,但是函数不会从 DLL 中导出,这使它毫无用处!
Google 搜索未产生(相关)结果;有没有人遇到过这个?我在 Visual Studio 2008 和 2010 上都进行了测试,结果是相同的。源文件包括 string.h 然后是这个文件 - 没有别的。
头文件:
#ifndef SECURE_STRING_H
#define SECURE_STRING_H
/* Provide MS Builds with import/export functionality
* BUILD_SECURE_STRING should be added to project preprocessor macros */
#if _WIN32
# if defined(BUILD_SECURE_STRING)
# define SECURESTRING_API __declspec(dllexport)
# else
# define SECURESTRING_API __declspec(dllimport)
# endif
#else
# define SECURESTRING_API
#endif
/* Windows on the whole, and glibc do not have/support strlc[at|py]
* This will almost certainly need revision for proper cross-platform checks */
#if _WIN32 || __GLIBC__ || !defined(HAVE_STRLCPY)
size_t SECURESTRING_API strlcat(char* dst, const char* src, size_t size);
size_t SECURESTRING_API strlcpy(char* dst, const char* src, size_t size);
#else
# define HAVE_STRLCPY 1
#endif
/* In case the active project has yet to include headers for 'BOOL' */
#ifndef BOOL
# define BOOL int
# define TRUE 1
# define FALSE 0
#endif
/*
| Locates 'search' within 'source', and if found, returns either the
| character itself, or the character after it if 'return_from_after_found'
| is TRUE.
| If it is not found, or any parameter is invalid, a NULL pointer is returned.
*/
char* SECURESTRING_API
str_from_last(char* source,
char search,
BOOL return_from_after_found);
#endif /* SECURE_STRING_H */
【问题讨论】:
-
BOOL宏看起来很可疑,可能它定义为不是类型的东西? -
遗憾的是,它在处理时是未定义的。删除定义显示该类型不存在。我刚刚用'int'替换了所有'BOOL',同样的错误又回来了。
标签: c visual-studio dll