When I do the transplant, the Embest IDE environment of the routine moved to the RealView MDK process, once encountered a problem: When the project was generated, the compilation passed all, but at the link prompt many symbols are undefined. If the reader has also encountered this problem, please continue to see if the link when prompted undefined variables are some inline functions (that is, using the keyword __inline). So that is the problem I have encountered. I hope this article will be of some help to you.
When using keyword __inline in MDK, in addition to the execution speed and the use of space and the normal function is not the same, there are the following is not the same as the normal function: the expression is, can not be declared as an external function, that is, the __ The inline function is defined in an external file and then declared as an extern type in the referenced file.
The reason is that the __inline function used in MDK has the same semantics as the inline function in standard C + +.
In the C + + standard, an inline function requires the same definition for each of its explanatory units, so that only internal links appear to be inline. It seems impossible to link and inline functions in an external file, especially if the external function is non-inline. In order for a function to be inline between different files, you must:
² Place These functions in a common header file, such as foo.h;
² Mark These functions as extern __inline;
² #include内联函数所在的头文件 When the inline function is required.
When the compiler decides not to inline a function, the function has only one copy after the link is compiled. Note: According to the author's experiment, it is also possible to define the inline function directly as __inline.
In MDK, if the __inline function is declared extern, it is passed at compile time and is said to be undefined at the time of linking. This is different from the Embest IDE. The Embest IDE allows inline functions to be defined in an external file, and in the referenced file, only the extern type can be declared as a compile link.
Workaround, define the inline function in the. h file, and include the header file in the file that you want to reference. This makes it possible to invoke the inline function in the header file. and can be correctly compiled, linked.
In fact, in the MDK at91rm9200 standard library is also done, AT91RM9200 Standard library has two. h Files ――at91rm9200.h and Lib_ AT91RM9200.h, where some constants and peripheral interface structures are defined in AT91RM9200.h. The library function is stored in lib_at91rm9200.h, and its library functions are all inline functions.
Note: The path of the above two header files is C:\Keil\ARM\INC\Atmel\RM9200. (where MDK installation path is C:\Keil)