C & C ++ systems often encounter multi-system inheritance, such as introducing a third-party library to an existing system or integrating several existing databases. Sometimes, we found that compilation and linking may cause some inexplicable and wonderful problems. The following describes the problems encountered:
1. Compilation Error
(1) the header file is not found.
This solution is relatively simple. First, determine whether the system does not reference the header file, and then determine whether the compiler can find the path of the header file.
(2) The type, variable, or function is not declared.
There are two scenarios:
A. There are multiple header files with the same name. As a result, the compiler does not actually need the header files.
Solution: Put the required header file path on the front.
B. The correct header file is referenced, and it is clearly declared or defined, or not found
The problem is probably due to Conditional compilation. Some macros defined in the compilation environment block the real definition. You can use # error "MSG" to test whether the compiler does not process the definition. Just open the macro.
2. Link error
Compilation errors are generally because the symbols are not found. There are two main types of errors:
(1). No symbols are defined.
There is no other way to add this.
(2). If you have defined a symbol and the link cannot be found, there are three situations:
A. Conditional compilation blocks function definitions
Check whether the compiler has compiled the required interface.
B. similar commands of nm can be used to check whether there is a symbolic definition. In this case, the most likely reason is. if the file name is duplicated, you can check the source file name of the symbol and modify it to the unique name.
C. when C ++ calls C functions, it will be considered to require name conversion by default. For example, the revert interface, C ++ will call interfaces similar to _ zxyrevert_sjx3, however, after the C source code is compiled, the generated symbol is _ revert.
You need to declare the C interface referenced in C ++ with extern "C", which is also the role of extern "C.
In summary, you must note that,C ++ references the C interface,Duplicate header file name,Source file name duplication, It will often lead to inexplicable problems, you need to pay attention!