c - strtok_s 在 os x 上未定义

标签 c string macos clang tr24731

我正在尝试使用 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。我做错了什么?

最佳答案

strtok_s 在 C11 中是可选的;老实说,只有 Windows 实现了它。使用 strtok_r在 POSIX 系统上。

关于c - strtok_s 在 os x 上未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49832455/

相关文章:

c - 如何用C语言编写命令行程序

C - read() 返回负数

java - 读取文件时如何跳过某些文本区域?

C++ getpid() 与 syscall(39)?

bash - 在 OS X : 'sed' 上使用 'find' 和 "invalid command code ."命令时出错

c - 出队在迭代中很奇怪,但在迭代之外并不奇怪

c - 为什么这个函数序言中没有 "sub rsp"指令,为什么函数参数存储在负 rbp 偏移处?

string - 如何编码 RDF N-Triples 字符串文字?

c++ - 这是违法的吧?

Python 启动器 Mac