How to add a library to the program code (if the library is not contained in the compiler)?

I need to insert commands from the Serial Gate library into the program, and for this I need to first enable this library, but I don’t know how to do this (

  • Must disappoint you - there are no libraries in the compiler = (do the old-fashioned way - import - Gorets
  • 2
    What kind of environment? In MVStudio, press alt + F7, find a place where libraries are included, and prescribe your own, and there is no business, so specify what you mean by the expression "How to add a library to the program code." - 3JIoi_Hy6
  • Where does it lie and what is called (file name)? And also, in such matters, write which OS and which compiler. - avp
  • And what a library. Or is it a library of object modules or dll - alexlz

4 answers 4

In C ++, libraries consist of header files (.h, .hh, .hpp) that the compiler needs (cl in Win, gcc in Linux) to compile object files from sources, and a binary module (static or dynamically loaded: .lib, .dll on Windows, .a, .so on Linux), with which object files are linked using a linker (link on Windows, ld on Linux), turning into an executable file or library.

"To add a library to the program code" translated into C ++ means to declare in the source code of the program a link to the header files of the library ("lock").

#include <mylib/mylib.h> 

After that, the program will be compiled into object files, but not linked, the linker will say that there are unknown characters in the object file. The linker needs to specify the path to the binary modules of the library. Then linking will happen and an executable file will be generated from the object files (or a library, depending on what you are compiling).

The compiler and linker are configured differently depending on the platform.

If something is not clear - ask, I will try to answer.

  • one
    With terms more carefully please. Since the "binary modules" in Unix-like systems are primarily executable files in binary codes (native or pseudo-code - java, mono, devil with horns), and include the object books ... (True, there are quite a few formats that can be used for downloads, and for linking - the same elf, for example) - alexlz
  • @alexlz Not-not, I called a binary module not an object object, but .so or .a (.lib, .dll). Edit: "unknown symbols in the binary module" - yes, I made a mistake here, now I will correct ... - weekens

man ld - the instruction to the linker (it is he who links the function calls in the program with the libraries) and builds the executable module.

If the question is more specific, please describe the specific problem.

    If this is Windows, and the library is dynamically loaded (DLL), then access to the functions is obtained by the standard LoadLibrary, GetProcAddress, FreeLibrary method. Read more here: use a DLL . If the library is connected statically (LIB), then you just need to register the necessary paths for the collector and add the necessary headers.

      Maybe something is needed: import function calls using __declspec (dllimport) ?