2013-10-29 15 views
5

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) 
+1

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

+0

Ok quindi è dovuto a __STRICT_ANSI__ in fase di definizione quando si utilizza -std = C++ 11 Posso capirlo da qui – odedsh

risposta

5

Quando si utilizza l'opzione -std = C++ 11 il compilatore -D__STRICT_ANSI__ definito che elimina la definizione di off_t lasciando solo _off_t definito.

Il compilatore è corretto, poiché off_t non è conforme allo standard.

Questo mi ha confuso perché volevo C++ 11 per le cose interessanti come nullptr & lambda. Non mi importava affatto di STRICT_ANSI.

La soluzione è quella di lavorare con -STD = gnu ++ 11

(Un'altra opzione è quella appena typedef off_t per i file header che ne hanno bisogno typedef _off_t off_t;)