我写了最小的测试问题:
#include <sys/types.h>
int main(int argc, char** argv) {
off_t l = 0;
return 0;
}
以下作品:g++ test.cpp
但如果我尝试用 c++11 编译,我会得到:
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
任何人都可以解释为什么会这样?这让我感到困扰的原因是我试图在我的 c++11 代码中使用 zlib 库。zlib.h 库经常使用 off_t。
我的编译器版本是: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)