Skip to main content

Command Palette

Search for a command to run...

Write a script that compiles a C file and creates an executable named myApp

Published
2 min read
Write a script that compiles a C file and creates an executable named myApp
D

Heya! 👋 I love helping people, and one of the best ways I do this is by sharing my knowledge and experiences. My journey reflects the power of growth and transformation, and I’m here to document and share it with you.

I started as a pharmacist, practicing at a tertiary hospital in the Northern Region of Ghana. There, I saw firsthand the challenges in healthcare delivery and became fascinated by how technology could offer solutions. This sparked my interest in digital health, a field I believe holds the key to revolutionizing healthcare.

Determined to contribute, I taught myself programming, mastering tools like HTML, CSS, JavaScript, React, PHP, and more. But I craved deeper knowledge and practical experience. That’s when I joined the ALX Software Engineering program, which became a turning point. Spending over 70 hours a week learning, coding, and collaborating, I transitioned fully into tech.

Today, I am a Software Engineer and Digital Health Solutions Architect, building and contributing to innovative digital health solutions. I combine my healthcare expertise with technical skills to create impactful tools that solve real-world problems in health delivery.

Imposter syndrome has been part of my journey, but I’ve learned to embrace it as a sign of growth. Livestreaming my learning process, receiving feedback, and building in public have been crucial in overcoming self-doubt. Each experience has strengthened my belief in showing up, staying consistent, and growing through challenges.

Through this platform, I document my lessons, challenges, and successes to inspire and guide others—whether you’re transitioning careers, exploring digital health, or diving into software development.

I believe in accountability and the value of shared growth. Your feedback keeps me grounded and motivated to continue this journey. Let’s connect, learn, and grow together! 🚀

The question above doesn't expect you to write a C program but rather a bash script that will be used for compiling various C programs.

This means you will need to know how to write bash scripts to be able to answer this question. If you don't know what a bash script is or how to write one, then check out my previous post on it.

How to write a script that performs certain commands in Linux

There are multiple ways to compile a C program into an executable file. One of the most common ways is:

  • using the gcc compiler

How to compile a C program using the gcc compiler

If you are using a Linux distro like ubuntu then you are likely to have the gcc compiler installed on it. Otherwise you can run the command below to install it.

sudo apt-get install build-essential

Once installed, you now have access to the gcc command.

To compile a C program with the gcc command, you need to pass the file containing your source code as an attribute to the command.

Let's assume that we have a file called app.c containing the source code of our C program, the gcc command will be:

gcc app.c

When the above command is run, all the four stages of the C program compilation will be completed and a final output file will be returned.

NB: The 4 stages of the compilation process are:

  1. Preprocessing
  2. Actual Compilation
  3. Assembly
  4. Linking

Hence, the gcc command above takes your source code through all these 4 stages and by default gives you an executable file with the name a.out.

What if you want the executable file to have a specific name?

You can add the option-o to the gcc command and give the name that you want for the execution file as an attribute.

gcc app.c -o myApp

The command above means that your source code app.c should be compiled into an executable file called myApp.

C Programming

Part 38 of 40

From today, I will be starting lessons on C programming in my ALX Software Engineering class and I look forward to sharing with you everything I learn through this series.

Up next

Write a script that compiles a C file but does not link

Bash script that does preprocessing, compiling, and assembly without linking

More from this blog

D

Dr. Ehoneah Obed

78 posts

Software engineer writing about systems: in code, in learning, in life. I reverse-engineer complex problems into frameworks. Pharmacist → SWE → Founder.