Exercise: Fix the Linker Error
Question
A beginner writes a small program across multiple files. The program uses a header file to share a global variable, but the code fails during linking with a multiple definition error.
Below is the compilation command.
gcc main.c helper.c -o program
This program typically fails with an error similar to: multiple definition of `count`.
Your task is to:
Fix the code so that it compiles and runs correctly.
Keep
countshared between both source files.
Exercise: Fix the Linker Error
Question
A beginner writes a small program across multiple files. The program uses a header file to share a global variable, but the code fails during linking with a multiple definition error.
Below is the compilation command.
gcc main.c helper.c -o program
This program typically fails with an error similar to: multiple definition of `count`.
Your task is to:
Fix the code so that it compiles and runs correctly.
Keep
countshared between both source files.
int count = 10;