definition of dllimport function not allowed

♀尐吖头ヾ 提交于 2019-12-19 22:02:15

问题


While compiling a C code, I'm getting the following error:

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

In the file stringop.c, I have the following function:

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 ;
}

And VL_EXPORT is defined as follows:

#      define VL_EXPORT extern "C" __declspec(dllimport)

Can somebody please tell me what is causing this error and how I can get rid of it?


回答1:


As documentation states, dllimport function are not allowed to have a body right there.

[...] 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



回答2:


You are saying that the function is external, defined in a Dll. And then you are defining it in your code. This is illegal since is has to be one or the other, but not both external and internal.

My guess is that you simply need to change dllimport to dllexport. I assume that you are building this code into a library.



来源:https://stackoverflow.com/questions/7657552/definition-of-dllimport-function-not-allowed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!