Я всегда получаю сообщение об ошибке во время компиляции, оно говорит о неопределенной ссылке на `strtok_r ', я использую MinGW в Windows 10, пожалуйста, помогите решить эту проблему.
#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);
};
}
Вот сообщения об ошибках и предупреждения в окнах 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