gpt4 book ai didi

c - 不允许定义 dllimport 函数

转载 作者:太空狗 更新时间:2023-10-29 15:33:36 25 4
gpt4 key购买 nike

在编译 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com