nlitsme / extfstools

Tools for extracting files from ext2,3,4 filesystem images
MIT License
121 stars 39 forks source link

‘size’(‘empty’) is not a member of ‘std’ #7

Closed neo1949 closed 4 years ago

neo1949 commented 4 years ago

Hi, I cloned the repo and try to build the project in linux visual studio code 1.47.1

I use the Code Runner plugin the compile this project, but get errors ‘size’ is not a member of ‘std’ and ‘empty’ is not a member of ‘std’:

[Running] cd "work/roms/extfstools-origin/" && make ext2rd && ./ext2rd && make clean
g++ -g -Wall -c -O3 -I itslib -D_UNIX -D_NO_RAPI -I /usr/local/include -I . -std=c++17  -MD ext2rd.cpp -o ext2rd.o 
In file included from ext2rd.cpp:14:0:
itslib/util/rw/OffsetReader.h: In constructor ‘OffsetReader::OffsetReader(ReadWriter_ptr, uint64_t, uint64_t)’:
itslib/util/rw/OffsetReader.h:16:84: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘uint64_t {aka long unsigned int}’ [-Wformat=]
             printf("off=%08llx, size=%08llx,  src: %08llx\n", off, size, _r->size());
                                                                                    ^
itslib/util/rw/OffsetReader.h:16:84: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 3 has type ‘uint64_t {aka long unsigned int}’ [-Wformat=]
itslib/util/rw/OffsetReader.h:16:84: warning: format ‘%llx’ expects argument of type ‘long long unsigned int’, but argument 4 has type ‘uint64_t {aka long unsigned int}’ [-Wformat=]
In file included from itslib/args.h:27:0,
                 from ext2rd.cpp:15:
itslib/stringutils.h: In function ‘std::__cxx11::string rhexdump(R)’:
itslib/stringutils.h:474:39: error: ‘size’ is not a member of ‘std’
     return hexdump(std::begin(range), std::size(range), sizeof(*std::begin(range)));
                                       ^
itslib/stringutils.h: In function ‘std::__cxx11::string base64_encode(const R&)’:
itslib/stringutils.h:554:9: error: ‘empty’ is not a member of ‘std’
     if (std::empty(data))
         ^

I have little knowledge about c++, could you give me some advice on how to fix the errors?

nlitsme commented 4 years ago

I don't never tried to use visual studio for this. I suggest you type make on the commandline, that should work. Another thing you may check, is if your gcc is recent enough, I know it works with gcc 8 and gcc 9.

neo1949 commented 4 years ago

Hi @nlitsme, thanks for your remind. I have already used the make command to build the project yesterday. It returned the same error as building with vs code. According to remind, it turned out to be my gcc version on ubuntu 14 is too old: gcc version on my ubuntu:

$ gcc --version
gcc (Ubuntu 5.5.0-12ubuntu1~16.04) 5.5.0 20171010
Copyright (C) 2015 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Refer to install gcc-9 on Ubuntu 18.04? to install gcc-9 and g++-9:

$ sudo apt-get install software-properties-common
$ sudo add-apt-repository ppa:jonathonf/gcc-9.0
$ sudo apt-get update
$ sudo apt-get install gcc-9
$ sudo apt-get install g++-9

Refer to How do I use the latest GCC on Ubuntu? to make gcc-9 as default gcc:

$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 1 --slave /usr/bin/g++ g++ /usr/bin/g++-5
update-alternatives: using /usr/bin/gcc-5 to provide /usr/bin/gcc (gcc) in auto mode
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 2 --slave /usr/bin/g++ g++ /usr/bin/g++-9
update-alternatives: using /usr/bin/gcc-9 to provide /usr/bin/gcc (gcc) in auto mode
$ gcc --version
gcc (Ubuntu 9.3.0-10ubuntu2~16.04) 9.3.0
Copyright (C) 2019 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

After setting gcc-9 as the default version, the project was built successfully with make:

$ make 
g++ -g -Wall -c -O3 -I itslib -D_UNIX -D_NO_RAPI -I /usr/local/include -I . -std=c++17  -MD ext2rd.cpp -o ext2rd.o
......
g++ -g -Wall -L/usr/local/lib -std=c++17 ext2dump.o stringutils.o -o ext2dump

Last but not least, thanks for your help!