我正在尝试使用应该在中定义的 C11 函数strtok_s<string.h>
,但是当我尝试使用它时,clang 给了我一个链接错误。编译这个程序:
#include <string.h>
int main() {
char * buffer;
char * state;
rsize_t strmax = 0;
char * fpl = strtok_s(buffer, &strmax, "\n", &state);
}
给我这个错误:
repro.c:7:15: warning: implicit declaration of function 'strtok_s' is invalid in
C99 [-Wimplicit-function-declaration]
char * fpl = strtok_s(buffer, &strmax, "\n", &state);
^
repro.c:7:9: warning: incompatible integer to pointer conversion initializing
'char *' with an expression of type 'int' [-Wint-conversion]
char * fpl = strtok_s(buffer, &strmax, "\n", &state);
^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
Undefined symbols for architecture x86_64:
"_strtok_s", referenced from:
_main in repro-3dcfc9.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我在 OS X 10.12.6 上使用 clang 8.1.0。我究竟做错了什么?