我正在使用 CodeBlocks 和 GCC 编译器。我想使用“字符串安全函数”,例如strlen_s
, strcpy_s
,但编译器显示错误:
对 strlen_s 的未定义引用。
然后我在代码中添加一行:
#define __STDC_WANT_LIB_EXT1__ 1
以及在编译器选项(设置 -> 编译器 -> 全局编译器设置 -> 其他编译器选项)中编写以下内容:
-std=c11
在我正在阅读的书中,有一段代码可以检查我的编译器是否支持这些功能。代码如下:
#include <stdio.h>
int main()
{
#if defined __STDC_WANT_LIB_EXT1__
printf("optional functions are defined");
#else
printf("optional functions are not defined");
#endif
return 0;
}
当我运行此代码时,我看到"optional functions are defined"。我还重新安装了 CodeBlocks,但仍然出现这些错误。
我应该安装另一个编译器吗?如果我应该,哪一个是最好的?