2017-10-07 275 views
0

我在编译使用GCC 4.4.7 hostscope(http://www.maier-komor.de/hostscope.html)得到一个错误GCC编译错误SCNu64在GCC 4.4.x到只有

OS:使用

[[email protected] hostscope-V2.1]$ uname -a 
Linux centos69 2.6.32-696.13.2.el6.x86_64 #1 SMP Thu Oct 5 21:22:16 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux 

GCC版本:

gcc(GCC)4.4.7 20120313(Red Hat 4.4.7-18)

[[email protected] hostscope-V2.1]$ make 
g++ -MM -g -Wall -DWFC -DVERSION=\"V2.1\" linuxdisk.cc > build/linuxdisk.d 
g++ -g -O2 -Wall -DWFC -DVERSION=\"V2.1\" -c linuxdisk.cc -o build/linuxdisk.o 
linuxdisk.cc: In function ‘void read_diskinfo(HostScope*)’: 
linuxdisk.cc:187: error: expected ‘)’ before ‘SCNu64’ 
linuxdisk.cc:199: warning: spurious trailing ‘%’ in format 
linuxdisk.cc:199: warning: too many arguments for format 
make: *** [build/linuxdisk.o] Error 1 
[[email protected] hostscope-V2.1]$ 

gcc抱怨的那一行是

182   uint64_t ts = get_us_time(); 
183   char *at = buf; 
184   for (;at && *at;) { 
185     uint64_t nrd, nmrd, nsecrd, msrd, nwr, nmwr, nsecwr, mswr, niop, msio, wmsio; 
186     char dev[32]; 
187     int f = sscanf(at,"%*u %*u %31s %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 " %" SCNu64 "" 
188         , dev 
189         , &nrd 
190         , &nmrd 
191         , &nsecrd 
192         , &msrd 
193         , &nwr 
194         , &nmwr 
195         , &nsecwr 
196         , &mswr 
197         , &niop 
198         , &msio 
199         , &wmsio); 
200     if (f == 0) 
201       return; 
202     at = strchr(at,'\n'); 

该包括在该源文件是

#include <dirent.h> 
#include <errno.h> 
#include <fcntl.h> 
#include <inttypes.h> 
#include <stdio.h> 
#include <stdlib.h> 
#include <string.h> 
#include <unistd.h> 

而SCNu64在inttypes.h

[[email protected] hostscope-V2.1]$ grep SCNu64 /usr/include/inttypes.h 
# define SCNu64  __PRI64_PREFIX "u" 

的hostscope编译没有与其他版本的GCC错误,定义如下

gcc(GCC)6.4.1 20170727(Red Hat 6.4.1-1)

GCC(GCC)4.8.5 20150623(红帽4.8.5-16)

GCC(GCC)5.3.1 20160406(红帽5.3.1-6)

,但不与GCC 4.4 .7

任何线索?

+0

Ve ry类似于https://stackoverflow.com/questions/8132399/how-to-printf-uint64-t-fails-with-spurious-trailing-in-format/8132440#8132440。尝试定义__STDC_FORMAT_MACROS或将'-D__STDC_FORMAT_MACROS'添加到Makefile中的g ++标志。 –

+0

[如何打印uint64 \ _t?失败:“格式为”的虚假拖尾'%'](https://stackoverflow.com/questions/8132399/how-to-printf-uint64-t-fails-with-spurious-trailing-in-format) – melpomene

回答

0

米哈伊尔的回答解决了这个问题

尝试定义__STDC_FORMAT_MACROS或添加-D__STDC_FORMAT_MACROS到g ++标志 在Makefile

非常感谢

贝恩德