ho scritto il più piccolo problema di test possibili:Mingw g ++ non riconosce off_t quando si compila con C++ 11
#include <sys/types.h>
int main(int argc, char** argv) {
off_t l = 0;
return 0;
}
le seguenti opere: g++ test.cpp
Ma se provo a compilare con c + +11 ottengo:
c: \ test> g ++ -std = C++ 11 test.cpp
test.cpp: In function 'int main(int, char**)':
test.cpp:5:2: error: 'off_t' was not declared in this scope
test.cpp:5:8: error: expected ';' before 'l'
test.cpp:6:9: error: 'l' was not declared in this scope
Chiunque può spiegare perché questo sta accadendo? Il motivo per cui mi dà fastidio è che sto cercando di usare la libreria zlib nel mio codice C++ 11. La libreria zlib.h usa molto poco.
La mia versione del compilatore è: gcc 4.7.2
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=c:/mingw/bin/../libexec/gcc/mingw32/4.7.2/lto-wrapper.exe
Target: mingw32
Configured with: ../gcc-4.7.2/configure --enable-languages=c,c++,ada,fortran,objc,obj-c++ --disable-sjlj-exceptions --with-dwarf2 --enable-shared --enable-libgomp --disable-win32-registry --enable-libstdcxx-debug --disable-build-poststage1-with-cxx --enable-version-specific-runtime-libs -build=mingw32 --prefix=/mingw
Thread model: win32
gcc version 4.7.2 (GCC)
Se confronto: 'g ++ -E test.cpp> test.c' &' g ++ -std = C++ 11 -E test.cpp> test.c' Posso vedere che senza C++ 11 ho 'typedef lungo _off_t; ' ' typedef _off_t off_t; ' e con std = C++ 11 ho solo' typedef long _off_t; ' – odedsh
Ok quindi è dovuto a __STRICT_ANSI__ in fase di definizione quando si utilizza -std = C++ 11 Posso capirlo da qui – odedsh