在编译 C 代码时,出现以下错误:
c:\users\kbarman\documents\mser\vlfeat-0.9.13-try\mser\stringop.c(71): error C2491: 'vl_string_parse_protocol' : definition of dllimport function not allowed
在文件 stringop.c 中,我有以下函数:
VL_EXPORT char *
vl_string_parse_protocol (char const *string, int *protocol)
{
char const * cpt ;
int dummy ;
/* handle the case prot = 0 */
if (protocol == 0)
protocol = &dummy ;
/* look for :// */
cpt = strstr(string, "://") ;
if (cpt == 0) {
*protocol = VL_PROT_NONE ;
cpt = string ;
}
else {
if (strncmp(string, "ascii", cpt - string) == 0) {
*protocol = VL_PROT_ASCII ;
}
else if (strncmp(string, "bin", cpt - string) == 0) {
*protocol = VL_PROT_BINARY ;
}
else {
*protocol = VL_PROT_UNKNOWN ;
}
cpt += 3 ;
}
return (char*) cpt ;
}
而VL_EXPORT定义如下:
# define VL_EXPORT extern "C" __declspec(dllimport)
谁能告诉我是什么导致了这个错误,我该如何摆脱它?
最佳答案
作为documentation states , dllimport
函数不允许在那里有一个主体。
[...] functions can be declared as dllimports but not defined as dllimports.
// function definition
void __declspec(dllimport) funcB() {} // C2491
// function declaration
void __declspec(dllimport) funcB(); // OK
关于c - 不允许定义 dllimport 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7657552/