2.2.7. Example: Building a C program with the GCC (compiling and linking in one step)


To build a basic C program, use GCC to compile source code directly into an executable. This single-step compilation command creates a foundation for developing simple applications on Red Hat Enterprise Linux.

Procedure

  1. Create a directory hello-c:

    $ mkdir hello-c
  2. Change to the created directory:

    $ cd hello-c
  3. Create file hello.c with the following contents:

    #include <stdio.h>
    
    int main() {
      printf("Hello, World!\n");
      return 0;
    }
  4. Compile and link the code with GCC:

    $ gcc hello.c -o helloworld

    This compiles the code, creates the object file hello.o, and links the executable file helloworld from the object file.

  5. Run the resulting executable file:

    $ ./helloworld
    Hello, World!
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

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

让开源更具包容性

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

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部