How can I create a C / C ++ program using "static linking" and "Dynamic linking" with gcc & Visual studio?

A library can be used in an application in two ways:

  • Statically stitched
  • Dynamically linked

But how to do this using both Visual Studio (Windows) and GCC?

I know that libraries are distributed only in these 4 ways:

  • Source
  • headers only libraries
  • *. lib files for windows. * .a for linux
  • *. dll (windows) and * .so (linux).

Source distribution just compiles. "Header-only libraries" is nothing more than the source distribution.

Now, if the desired library is distributed in the form *. lib . To use it.

In Visual Stuido :

  • , (*. h), > >
  • *.lib Configuration Properties > Linker > Input > Additional Dependencies
  • *.lib : > p >

GCC/MingW? , , *.dll *.so . - , Visual Studio (Windows) GCC (linux)/mingw (windows)

+3
2

GCC . , glib-2.0.lib, , GLib, - my_prog.c, GCC gcc my_prog.c -L<library_dir_here> -lglib-2.0.

dll, - , , . , , . . Windows LoadLibrary, Linux dlopen. ( dll ) , . , , , GetProcAddress Windows dlsym Linux; , . , , " " (.. ) .

+3

DLL- .lib . ( # 3)

DLL. LIB DLL.

//

  • LIB , # 3 . , DLL , .

  • "LoadLibrary()" / LIB .

gcc.

+1

Source: https://habr.com/ru/post/1732421/


All Articles