Site icon ucdev

How to deal with llvm-include-order error

Side shot of a code editor using react js and its hooks

If your compilation gets stuck on an error „improper include order”, this means you are using clang-tidy with enabled checks for correct order of included header files. Of course, the simple solution to that is to try to move problematic lines up or down and try again until they are success. But if you don’t understand what is the rule behind this order, you will probably make the same mistake in the future. The good news is that in this article I will explain it so you can avoid it in the future.

Before we start with the main topic, let’s explain one thing, because many people probably wonder if this check is necessary? No, it’s not, but it helps ensure consistency and readability in your code, so I would recommend you to try using this order:

Below there is a general example for this order:

// Main header file for this implementation file.
#include "my_lib.h"

// System headers.
#include <unistd.h>

// C standard library headers.
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdint.h>

// Other libraries' headers.
#include <cjson/cjson.h>

// Project headers.
#include "foo/foo.h"
#include "bar/bar.h"
#include "some_module/my_module.h"

This is the end. Thanks for reading this article. I hope it will be usefull. Happy coding 🙂

Exit mobile version