简体   繁体   English

未定义对“ strtok_r” Windows 10 MinGW的引用

[英]undefined reference to `strtok_r' Windows 10 MinGW

i am always getting error while compile , it's saying undefined reference to `strtok_r' i am using MinGW in windows 10 , please help to solve this issue. 我在编译时总是出错,它是对`strtok_r'的未定义引用,我在Windows 10中使用MinGW,请帮助解决此问题。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>


int main(int argc, char **argv) {
  char *test1, *test2;
  char *state1, *state2;
  char *cur1, *cur2;

  test1 = malloc(20);
  test2 = malloc(20);
  strcpy(test1, "a,b,c,d");
  strcpy(test2, "e,f,g,h");

  cur1 = strtok_r(test1, ",", &state1);
  cur2 = strtok_r(test2, ",", &state2);
  while (cur1 != NULL && cur2 != NULL) {
    if (cur1 != NULL) {
      printf("cur1 : %s\n", cur1);
    }
    if (cur2 != NULL) {
      printf("cur2 : %s\n", cur2);
    }
    cur1 = strtok_r(NULL, ",", &state1);
    cur2 = strtok_r(NULL, ",", &state2);
  };
}

Here is error and warning messages in windows 10 这是Windows 10中的错误和警告消息

strtok-test.c: In function 'main':
strtok-test.c:16:10: warning: implicit declaration of function 'strtok_r' [-Wimplicit-function-declaration]
   cur1 = strtok_r(test1, ",", &state1);
          ^~~~~~~~
strtok-test.c:16:8: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
   cur1 = strtok_r(test1, ",", &state1);
        ^
strtok-test.c:17:8: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
   cur2 = strtok_r(test2, ",", &state2);
        ^
strtok-test.c:25:10: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
     cur1 = strtok_r(NULL, ",", &state1);
          ^
strtok-test.c:26:10: warning: assignment makes pointer from integer without a cast [-Wint-conversion]
     cur2 = strtok_r(NULL, ",", &state2);
      ^
C:\Users\AppData\Local\Temp\ccvzdBJh.o: In function `main':
C:\Users\Desktop\New folder/strtok-test.c:16: undefined reference to `strtok_r'
C:\Users\Desktop\New folder/strtok-test.c:17: undefined reference to `strtok_r'
C:\Users\Desktop\New folder/strtok-test.c:25: undefined reference to `strtok_r'
C:\Users\Desktop\New folder/strtok-test.c:26: undefined reference to `strtok_r'
collect2.exe: error: ld returned 1 exit status

strtok_r is not a standard C method (it is POSIX). strtok_r不是标准的C方法(它是POSIX)。 Your compiler may not be POSIX compliant and therefore its standard library might not contain the method. 您的编译器可能不符合POSIX,因此其标准库可能不包含该方法。 Look in your string.h file and see whether its prototype is declared there. 查看您的string.h文件,看看是否在其中声明了其原型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM