簡體   English   中英

在OS X上未定義strtok_s

[英]strtok_s is undefined on os x

我正在嘗試使用C11函數strtok_s ,該函數應該在<string.h>定義,但是當我嘗試使用c11時 ,它給了我一個鏈接錯誤。 編譯程序:

#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。 我究竟做錯了什么?

在C11中strtok_s是可選的; 老實說,只有Windows實現了它。 在POSIX系統上使用strtok_r

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

由於所有的邊界檢查功能, 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