Visual Studio和GCC - 编译器差异

时间:2015-01-27 21:19:46

标签: c linux gcc

在VS中编译我没有错误但是使用gcc我得到以下内容:

warning: format ‘%Lf’ expects argument of type ‘long double *’, but argument 2 has type ‘double *’ [-Wformat=]
  scanf("%Lf",&checkprice);
  ^
/tmp/cch8NUeU.o: In function `main':
test.c:(.text+0x8e1): undefined reference to `stricmp'
collect2: error: ld returned 1 exit status

我猜这是正常的。我怎样才能在gcc中修复它?

1 个答案:

答案 0 :(得分:4)

stricmp()不是一个标准函数,虽然有一个POSIX等效strcasecmp()所以你的代码可以与两个编译器无缝地编译,你可以添加这样的东西

#ifdef __GNUC__
#define _stricmp strcasecmp
#endif

并使用_stricmp(),因为stricmp()deprecated

同时修复scanf()格式说明符,或将目标变量类型更改为long double