2

测试.cpp

#include <cstdio>
#include <cstddef>
using std::size_t;

编译:

 >  g++ -c test.cpp -o test.o     
In file included from /.../include/stdio.h:75:0,
                 from /.../gcc/include/c++/cstdio:42,
                 from test.cpp:1:
test.cpp:3:12: error: expected unqualified-id before ‘int’
 using std::size_t;
            ^
test.cpp:3:12: error: expected ‘;’ before ‘int’
test.cpp:3:12: error: declaration does not declare anything [-fpermissive]

如果我只删除#include <cstdio>,一切正常。
但如果我只删除#include <cstddef>,同样的错误会弹出。
如果我同时删除:

 >  g++ -c test.cpp -o test.o    
test.cpp:1:12: error: ‘std::size_t’ has not been declared
 using std::size_t;
            ^

我需要包含和std::size_t使用这两个库。
在这种情况下我该怎么办?我应该添加一些CXXFLAGS吗?

我的 gcc 版本是 4.8.5。

 >  g++ --version 
g++ (GCC) 4.8.5
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.

更新:

我试过系统默认的 gcc: /usr/bin/g++,错误消失了。
所以应该归咎于anaconda的gcc。我将向小组提出一个问题。
谢谢你们。

4

0 回答 0