C notes _ dynamic and static libraries

1, static library

  • create
    • Project configuration property is set to a static library lib, edit files, and .h .c files can be generated.
  • use
    • method one:
      • Add the header file directory of the project: Project properties --- --- Configuration Properties --- c / c ++ --- General --- Additional include directories: add the header file storage directory.
      • Add file references a static library lib path: Project properties --- --- --- Configuration Properties Linker --- --- Additional conventional library catalog: plus lib file storage directory.
      • Then add a project reference to the lib file name: Project properties --- --- --- Configuration Properties Linker Input --- --- Additional Dependencies: add lib file name.
    • Method Two:
      • #pragma comment(lib,"./mylib.lib")
    • Method three:
      • Like adding .h and .c files, add the lib file to the project file list to go.
      • Switch to the "solution view" ---> you want to add lib project -> right click -> "Add" -> "Existing Item" -> lib Select File -> OK.

2, dynamic library

  • create

    • Project configuration property is set to dll static library files and edit .h .c files;

      Header file declared as __declspec (dllexport) function declaration;

      ​ 例:__declspec(dllexport) int MyNum(int a, int b)

  • use

    • method one:

      #pragma comment(lib,"./mydll.lib")

    • Method Two:

      HANDLE hDll;

      hDll = LoadLibrary("mydll.dll");

3, the advantages and disadvantages

  • Static library advantages and disadvantages:
    • Static library for linked library is on the compile-time completion of the static library is copied to the program at the link stage of the program, and when the program is running does not matter;
    • Program at run-time libraries with no connection to facilitate the transplant.
    • Waste of space and resources, all object files and libraries involved are linked into one executable file.

Guess you like

Origin www.cnblogs.com/chungeyuan/p/11410260.html