You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

g++默认包含哪些库?库范围确认及文档查询咨询

Great question! Your assumption is mostly correct, but there's a small but important detail to add. Let's break this down clearly:

Default Libraries g++ Includes Automatically

When you compile a C++ program with g++, it automatically links against two key standard libraries by default:

  • The GNU C++ Standard Library (libstdc++): This is exactly what you're thinking—all the standard C++ features (STL containers, algorithms, iostream, exception handling, etc.) are part of this library. It's g++'s implementation of the C++ standard, included without needing any extra flags.
  • The GNU C Standard Library (libc): Since C++ maintains core compatibility with C, g++ links against the C standard library by default too. This covers core C functions like malloc, printf, and string manipulation routines that the C++ runtime relies on (even if you don't explicitly call them in your code).

Additionally, g++ includes a minimal runtime support layer (part of libstdc++) that handles things like initializing global objects, setting up exception handling, and cleaning up resources when your program exits—this is all part of the default setup.

Libraries NOT Included by Default

Any non-standard or third-party libraries (like Boost, Qt, SDL, or custom libraries you've built) are not linked automatically. You have to tell g++ to include them explicitly using flags:

  • Use -l<library-name> to link against a system library (e.g., -lboost_system for Boost's system module, -lsdl2 for SDL2).
  • For some optional standard components (like the C++ Thread Library on older systems), you might need to add -pthread to enable full threading support.
Official Documentation Sources

To get authoritative details on g++'s default behavior and the libstdc++ library:

  • Local Man Pages: Run man g++ in your terminal to see command-line options and default linking behavior. For libstdc++, check man libstdc++ (if available on your system) or look for the libstdc++ documentation in the GCC info pages (run info libstdc++).
  • GCC Official Docs: The GNU Compiler Collection's official documentation includes comprehensive guides for g++ and libstdc++. These cover everything from default libraries to advanced linking options—they're often included with your GCC installation or accessible through system documentation tools.

内容的提问来源于stack exchange,提问作者AmphotericLewisAcid

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 10:06:06