简体   繁体   English

在OS X上未定义strtok_s

[英]strtok_s is undefined on os x

I'm trying to use the C11 function strtok_s , which is supposed to be defined in <string.h> , but clang is giving me a linking error when I try to use it. 我正在尝试使用C11函数strtok_s ,该函数应该在<string.h>定义,但是当我尝试使用c11时 ,它给了我一个链接错误。 Compiling this program: 编译程序:

#include <string.h>

int main() {
    char * buffer;
    char * state;
    rsize_t strmax = 0;
    char * fpl = strtok_s(buffer, &strmax, "\n", &state);
}

Gives me this error: 给我这个错误:

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)

I'm using clang 8.1.0 on OS X 10.12.6. 我在OS X 10.12.6上使用clang 8.1.0。 What am I doing wrong? 我究竟做错了什么?

strtok_s is optional in C11; 在C11中strtok_s是可选的; honestly only Windows implements it. 老实说,只有Windows实现了它。 Use strtok_r on POSIX systems. 在POSIX系统上使用strtok_r

http://en.cppreference.com/w/c/string/byte/strtok : http://en.cppreference.com/w/c/string/byte/strtok

As all bounds-checked functions, strtok_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including string.h . 由于所有的边界检查功能, strtok_s仅保证可供如果__STDC_LIB_EXT1__由实现所定义,并且如果用户定义__STDC_WANT_LIB_EXT1__为整数常数1包括前string.h

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

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