0

I get an error while compiling hostscope (http://www.maier-komor.de/hostscope.html) using GCC 4.4.7

OS:

[xtrnaw7@centos69 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 version used:

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

[xtrnaw7@centos69 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
[xtrnaw7@centos69 hostscope-V2.1]$ 

The line the gcc is complaining about is

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');

The includes in this source file are

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

And SCNu64 is defined in inttypes.h

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

The hostscope compiles without error with other GCC versions , like

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

gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16)

gcc (GCC) 5.3.1 20160406 (Red Hat 5.3.1-6)

but not with GCC 4.4.7

Any clues?

bnsmb01
  • 1
  • 1
  • Very similar to https://stackoverflow.com/questions/8132399/how-to-printf-uint64-t-fails-with-spurious-trailing-in-format/8132440#8132440. Try defining __STDC_FORMAT_MACROS or adding `-D__STDC_FORMAT_MACROS` to g++ flags in the Makefile. – Mikhail Maltsev Oct 08 '17 at 02:12
  • Possible duplicate of [How to printf uint64\_t? Fails with: "spurious trailing ‘%’ in format"](https://stackoverflow.com/questions/8132399/how-to-printf-uint64-t-fails-with-spurious-trailing-in-format) – melpomene Oct 08 '17 at 10:35

1 Answers1

0

the answer of Mikhail solved the problem

Try defining __STDC_FORMAT_MACROS or adding -D__STDC_FORMAT_MACROS to g++ flags in the Makefile

Thanks a lot

Bernd

bnsmb01
  • 1
  • 1