int64 max linux,gcc – ‘INTMAX_MAX’未在此范围内声明

编译简单代码片段时:test.cpp:

#include

#include

int main()

{

intmax_t max = INTMAX_MAX;

printf("%jd", max);

return 0;

}

我收到此错误:

[huqiu@101 ~]$g++ -o test.o test.cpp

test.cpp: In function ‘int main()’:

test.cpp:5: error: ‘INTMAX_MAX’ was not declared in this scope

我做了什么:

编译器信息:

[huqiu@101 ~]$which g++

/usr/bin/g++

和版本:

[huqiu@101 ~]$g++ -v

Using built-in specs.

Target: x86_64-redhat-linux

Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre

--enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-ppl --with-cloog --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux

Thread model: posix

gcc version 4.4.7 20120313 (Red Hat 4.4.7-4) (GCC)

我检查了包含路径:

[huqiu@101 ~]$gcc -o test.o test.cpp -v

...

COLLECT_GCC_OPTIONS='-o' 'test.o' '-v' '-mtune=generic'

/usr/libexec/gcc/x86_64-redhat-linux/4.4.7/cc1plus -quiet -v -D_GNU_SOURCE test.cpp -quiet -dumpbase test.cpp -mtune=generic -auxbase test -version -o /tmp/ccjZyOY4.s

ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include-fixed"

ignoring nonexistent directory "/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../x86_64-redhat-linux/include"

#include "..." search starts here:

#include <...> search starts here:

/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7

/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/x86_64-redhat-linux

/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../include/c++/4.4.7/backward

/usr/local/include

/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include

/usr/include

End of search list.

GNU C++ (GCC) version 4.4.7 20120313 (Red Hat 4.4.7-4) (x86_64-redhat-linux)

compiled by GNU C version 4.4.7 20120313 (Red Hat 4.4.7-4), GMP version 4.3.1, MPFR version 2.4.1.

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072

Compiler executable checksum: 9beacdb5724f8325308f81d8bbfbf884

test.cpp: In function ‘int main()’:

test.cpp:5: error: ‘INTMAX_MAX’ was not declared in this scope

还有依赖:

[huqiu@101 ~]$gcc -M test.cpp

test.o: test.cpp /usr/include/stdint.h /usr/include/features.h \

/usr/include/sys/cdefs.h /usr/include/bits/wordsize.h \

/usr/include/gnu/stubs.h /usr/include/gnu/stubs-64.h \

/usr/include/bits/wchar.h /usr/include/stdio.h \

/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stddef.h \

/usr/include/bits/types.h /usr/include/bits/typesizes.h \

/usr/include/libio.h /usr/include/_G_config.h /usr/include/wchar.h \

/usr/lib/gcc/x86_64-redhat-linux/4.4.7/include/stdarg.h \

/usr/include/bits/stdio_lim.h /usr/include/bits/sys_errlist.h

我确信stdint.h存在于/usr/include中:

[huqiu@101 ~]$cat /usr/include/stdint.h |grep INTMAX_MAX

# define INTMAX_MAX (__INT64_C(9223372036854775807))

# define UINTMAX_MAX (__UINT64_C(18446744073709551615))

gcc -E

[huqiu@101 ~]$gcc -E test.cpp | grep INTMAX_MAX

intmax_t max = INTMAX_MAX;

我该怎么办?

一切看起来都合适.我在其他gcc版本较低的机器上成功编译了代码,例如4.2.x.

我认为可能有一些重要的事情让我弄错了.

任何帮助和提示都会很棒.提前致谢 :)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
这个错误是由于链接器无法找到对应的函数或变量的定义而导致的。在你的问题中,出现了三个不同的错误,分别是undefined reference to `WinMain'、undefined reference to `stack::push'和undefined reference to `main'。这些错误都是由于缺少对应的函数或变量的定义引起的。 对于undefined reference to `WinMain'错误,这通常是由于缺少main函数引起的。在C++程序中,main函数是程序的入口,如果缺少main函数,链接器就无法找到程序的入口点,从而报错。你需要确保你的程序中有一个正确的main函数。 对于undefined reference to `stack::push'错误,这可能是由于你的程序中使用了stack类的push函数,但是没有提供对应的定义。你需要检查你的程序中是否有对stack类的push函数进行定义。 对于undefined reference to `main'错误,这通常是由于缺少main函数的定义引起的。你需要确保你的程序中有一个正确的main函数,并且在编译时将其包含在编译范围内。 至于你提到的undefined reference to `max(int, int)'错误,这可能是由于你在程序中使用了max函数,但是没有提供对应的定义。你需要检查你的程序中是否有对max函数进行定义。 综上所述,你需要检查你的程序中是否缺少对应函数或变量的定义,并确保它们在编译时被正确地包含在编译范围内。 #### 引用[.reference_title] - *1* [undefined reference to `WinMain‘ collect2.exe: error: ld returned 1 exit status的处理方法](https://blog.csdn.net/weixin_43064827/article/details/120323886)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [vscode文件编译问题undefined reference to... collect2.exe: error: ld returned 1 exit status](https://blog.csdn.net/sinat_41053216/article/details/128783715)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [gcc报(.text+0x24): undefined reference to `main‘collect2: error: ld returned 1 exit status解决方法](https://blog.csdn.net/qysh123/article/details/119460526)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值