Bird
0
0

You have two C files: main.c and utils.c. You compile them separately with gcc -c main.c and gcc -c utils.c. What is the correct command to create an executable named app linking both object files?

hard📝 Application Q15 of 15
C - Basics and Execution Environment
You have two C files: main.c and utils.c. You compile them separately with gcc -c main.c and gcc -c utils.c. What is the correct command to create an executable named app linking both object files?
Agcc main.o utils.o -o app
Bgcc main.c utils.c -c -o app
Cgcc -o app main.c utils.c
Dgcc -c main.o utils.o -o app
Step-by-Step Solution
Solution:
  1. Step 1: Understand separate compilation

    Compiling with '-c' creates object files (.o) without linking.
  2. Step 2: Link object files to create executable

    Use 'gcc main.o utils.o -o app' to link object files into executable named 'app'.
  3. Final Answer:

    gcc main.o utils.o -o app -> Option A
  4. Quick Check:

    Link object files with gcc -o app [OK]
Quick Trick: Link .o files with gcc -o executable_name [OK]
Common Mistakes:
  • Using -c flag during linking
  • Trying to compile .o files directly
  • Mixing source and object files incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More C Quizzes