2017-10-07 276 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

非常感謝

貝恩德