c - 不允许定义 dllimport 函数

标签 c dllimport

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

相关文章:

c - 使用 C 中的指针交换结构体内部二维数组的行

c++ - C 风格字符串、指针、数组

c - 使 Microsoft Visual Studio 在变量声明之前接受逻辑检查/函数调用的选项?

c# - 使用 DllImport 在 C# 中调用 OpenGL 函数?

c# - 将 C# 字符串数组传递给 C++ DLL 并在那里进行修改

c - 从字符串中读取 char 类型并将其数值分配给 int 类型结构成员

c - strlen() 即使在空终止符之后也会计算字符数

c++ - 安装 msvcr90.dll 的简单方法! (没有 C++ 可再发行组件包)

C# 使用导入的非强名称库构建强名称文件

f# - F# 中的枚举 Windows