开发者

definition of dllimport function not allowed

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(strin开发者_Go百科g, "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?


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜