首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >明威g++在用c++11编译时不识别c++11

明威g++在用c++11编译时不识别c++11
EN

Stack Overflow用户
提问于 2013-10-29 18:44:52
回答 1查看 2.8K关注 0票数 5

我写了一个最小的可能的测试题:

代码语言:javascript
复制
#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

代码语言:javascript
复制
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库。H库经常使用off_t。

我的编译器版本是: gcc 4.7.2

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-10-29 19:10:36

当使用选项-std=c++11时,编译器定义了-D__STRICT_ANSI__,它删除了off_t的定义,只保留了定义的_off_t。

编译器这样做是正确的,因为off_t不符合标准。

这让我很困惑,因为我想要c++11做一些很酷的东西,比如nullptr & lambdas。我根本不在乎STRICT_ANSI。

解决方案是使用-std=gnu++11

(另一种选择是只对需要typedef _off_t off_t的头文件进行typedef _off_t off_t;)

票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19666666

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档