How to fix GCC error: implicit declaration of function ...

Problem:

While trying to compile your C/C++ program, you see an error message like

../src/main.c:48:9: error: implicit declaration of function 'StartBenchmark' [-Werror=implicit-function-declaration]
         StartBenchmark();

Solution:

implicit declaration of function means that you are trying to use a function that has not been declared. In our example above, StartBenchmark is the function that is implicitly declared.

This is how you call a function:

StartBenchmark();

This is how you declare a function:

void StartBenchmark();

The following bullet points list the most common reasons and how to fix them:

  1. Missing #include: Check if the header file that contains the declaration of the function is #included in each file where you call the function (especially the file that is listed in the error message), beforethe first call of the function (typically at the top of the file). Header files can be included via other headers,
  2. Function name typo: Often the function name of the declarationdoes not exactly match the function name that is being *called.*For example, startBenchmark() is declared while StartBenchmark() is being called. I recommend to fix this by copy-&-pasting the function name from the declaration to wherever you call it.
  3. Bad include guard: The include guard that is auto-generated by IDEs often looks like this:
#ifndef _EXAMPLE_FILE_NAME_H
#define _EXAMPLE_FILE_NAME_H
// ...
#endif

Note that the include guard definition _EXAMPLE_FILE_NAME_H is not specific to the header filename that we are using (for example Benchmark.h). Just the first of all header file names wil 4. **Change the order of the #include statements:**While this might seem like a bad hack, it often works just fine. Just move the #include statements of the header file containing the declaration **to the top.**For example, before the move:

#include "Benchmark.h"
#include "other_header.h"

after the move:

#include "Benchmark.h"
#include "other_header.h"