【发布时间】:2017-05-10 12:48:04
【问题描述】:
我使用 Homebrew 在 OSX 10.12 上安装了 GCC 5、6 和 7。编译简单代码
#include <iostream>
int main() {
uint foo = 10;
std::cout << foo << std::endl;
}
返回错误:
$ g++-7 -o uint uint.cpp
uint.cpp: In function 'int main()':
uint.cpp:5:5: error: 'uint' was not declared in this scope
uint foo = 10;
^~~~
uint.cpp:5:5: note: suggested alternative: 'int'
uint foo = 10;
^~~~
int
uint.cpp:6:18: error: 'foo' was not declared in this scope
std::cout << foo << std::endl;
^~~
uint.cpp:6:18: note: suggested alternative: 'feof'
std::cout << foo << std::endl;
^~~
feof
我可以访问的其他编译器不会发生此错误。该代码适用于 clang++(在 OSX 上)和 gcc4/5/6 在 Linux 系统上。 我这边是否缺少配置开关?或者这可能是因为 gcc 与 libstdc++ 链接而不是与 OSX 标准的 libc++ 链接?
【问题讨论】:
-
uint不是关键字,stdint.h 没有声明它。你认为它应该来自哪里? -
你认为
uint是什么?uintN_t、uint_leastN_t和uint_fastN_t形式中有类型,但不仅仅是uint本身。 -
好吧,我可以做一个
typedef uint unsigned int,但这并不能回答我的问题。 -
您要查找的标志是
-Duint="unsigned int"。我当然是在开玩笑……但它确实有效。 -
你好像忘记了
#include "uint.h"。