export , import and extern in C language mixed programming

http://blog.csdn.net/simanstar/article/details/22384961

[IMPORT]:
  Syntax format: 
  IMPORT symbol {[WEAK]} 
  The IMPORT pseudo-operation tells the compiler that the current symbol is not defined in this source file, but is defined in other source files, and this symbol may be referenced in this source file, And regardless of whether the source file actually refers to the symbol, the symbol will be added to the symbol table of the source file. (The difference from EXTERN below) 
  Symbols are case-sensitive in the program. [WEAK] After specifying this option, if the symbol is not defined in all source files, the compiler will not generate any error message, and compile The compiler will also not look for the symbol in a library that is not currently INCLUDE in.
  Use the IMPORT pseudo-operation to declare that a symbol is defined in another source file. If the linker cannot resolve the symbol during connection processing, and the [WEAK] option is not specified in the IMPORT pseudo-operation, the linker reports an error. If the linker cannot resolve the symbol during connection processing, and the [WEAK] option is specified in the IMPORT pseudo-operation, the linker will not report an error, but will do the following:
  1) If the symbol is blocked by a B or BL instruction Reference, the symbol is set to the address of the next instruction, the B or BL instruction is equivalent to a NOP instruction
  2) In other cases, the symbol is set to 0.
  Example of use: 
  AREA Init , CODE , READONLY 
  IMPORT Main ; notify the compiler The current file should refer to the label Main, but Main is defined in other source files... 
  END 
[EXTERN]: 
  Syntax format: 
  EXTERN symbol {[WEAK]} 
  The EXTERN pseudo-operation tells the compiler that the current symbol is not defined in this source file, but is defined in other source files, and the symbol may be referenced in this source file. If the source file does not actually reference the symbol, the symbol will not be added to the symbol table of the source file.
  Note: The difference from IMPORT
  Example of use: 
  AREA Init , CODE , READONLY 
  EXTERN Main ; inform the compiler that the current file should refer to the label Main, but Main is defined in other source files... 
  END 

【EXPORT】:

EXPORT_SYMBOL is a macro to create a new entry for this function, including its address and name. This function will be placed in the __ksymtab section of the kernel image. When the module that uses this function is loaded at runtime, the loader parses the function from the __ksymtab section.

      Example of use:

      AREA adrlabel, CODE, READONLY
        
      IMPORT Good
      EXPORT Start
        
      ENTRY                     
Start

      MOV R0,#10 ; useless, purely for convenience to see
      B Good
      B .

      END

This declares a Start label for external reference, and then the IMPORT statement needs to refer to a C language Good function .


【summary】

IMPORT 和EXTERN ,定义表示这是一个外部变量的标号,不是在本程序定义的

EXPORT ,表示本程序里面用到的变量提供给其他模块调用的。


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325482200&siteId=291194637