2.2.6. Linking code to create executable files


To create an executable file, linking combines all object files and libraries. This is the final step when building a C or C++ application.

Prerequisites

Procedure

  1. Change to the directory containing the object code file(s).
  2. Run gcc:

    $ gcc ... objfile.o another_object.o ... -o executable-file

    An executable file named executable-file is created from the supplied object files and libraries. To link additional libraries, add the required options after the list of object files.

    For more information, see Using libraries with GCC.

    注意

    With C++ source code, replace the gcc command with g++ for convenient handling of C++ Standard Library dependencies.

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部