error: conflicting types for error reasons and solutions

Reason one

There is no function declaration, and the function is defined after the main function

Cause two

The header files are cyclically referenced, consider the order of inclusion
or use

#ifndef CAPITAL_FILENAME
#define CAPITAL_FILENAME

// main body

#endif /* CAPITAL_FILENAME */

Reason three

The header file function declaration and function definition parameters are different, such as

The header file declares void test(const char* buf), but it is written as void test(char* buf);

Reason four

The parameter type used by the function is a custom type (such as a structure), and the definition of a custom type is between the declaration of the function and the definition of the function, because in the function declaration, the structure does not

It is not defined and is not recognized as a structure by the system. When the function is defined later, the structure is already defined and the system recognizes it as a structure, which causes the system to think that the declaration and definition use different parameter types; therefore, the above problem;

Reason 5

In Linux, when compiling the header file, an intermediate precompiled file (.h.gch) will appear. When the entire file is compiled again, if the file (.h.gch) exists, the file (.h) will be used directly. .gch) instead of compiling the .h file. At this time, if you change the .h file and continue to compile, it will cause inconsistencies between the declaration and the definition. Although the declaration and definition are consistent in the file, But in fact, the system does not use the file (.h) you changed when compiling, but directly uses the .h.gch file you compiled before modification (this error is generally difficult to find, if you find it in your own directory. h.gch file must be updated in time).

Reference

https://blog.51cto.com/10901086/1903340

Guess you like

Origin blog.csdn.net/weixin_39591031/article/details/112824488