我正在运行OS X Sierra并尝试编译使用strcpy_s ac程序,但是我安装的clang编译器正在使用c99标准,但是从我的阅读中来看strcpy_s需要c11。
这是我要编译的代码
#include
#include
#include
int main(void)
{
char source[] = "Test string";
char destination[50];
if(strcpy_s(destination, sizeof(destination), source))
printf("string copied - %s",destination);
return 0;
}
这是我用来编译的命令
$ clang copytest.c -o copytest
copytest.c:11:5: warning: implicit declaration of function 'strcpy_s' is invalid in C99 [-Wimplicit-function-declaration]
if(strcpy_s(copied_string, sizeof(copied_string), source))
^
1 warning generated.
Undefined symbols for architecture x86_64:
"_strcpy_s", referenced from:
_main in copytest-e1e05a.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
我尝试使用标准标志进行编译...
clang -std=c11 copytest.c -o copytest
但是我得到了完全相同的“在c99中无效”警告。 我也尝试使用gcc进行编译,但仍然收到相同的c99警告。
我尝试通过自制程序进行升级,显示以下内容
警告:gcc 9.2.0已经安装并且是最新的
我有clang版本9.0.0
$ clang -v
Apple LLVM version 9.0.0 (clang-900.0.39.2)
我的xcode版本是Xcode 9.2,从我读过的所有内容中都应该带有c11支持。
我在编译时做错什么了吗,我的代码本身是错误的吗? 这是我在这里发现的唯一类似问题,但甚至没有答案。 谢谢