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 (
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 (
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.
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) ?
Source: https://ru.stackoverflow.com/questions/43186/
All Articles