Linking to the correct library

I do not think my question here was given here. So, here it is, I have a static library that I maintain and update periodically. I am also updating the version number correctly. Now my application using this library should refer to the same version of the library, and not to older or older ones. One thing I tried is to use predefined macros in the library header file and check it in your application. It worked, but that way you can only provide the correct header files. Is there any method to prevent the link from working if it's the wrong library? I hope the question is somewhat clear.

Hari

+3
source share
2 answers

I'm not sure I recommend it, but ...

The title may include:

#define LIB_VERSION_SUFFIX _3_17

#define LIB_PASTER(x, y)    x ## y
#define LIB_EVALUATOR(x, y) LIB_PASTER(x, y)
#define LIB_FUNCTION(x)     LIB_EVALUATOR(x, LIB_VERSION_SUFFIX)

#define lib_functionA LIB_FUNCTION(lib_functionA)

extern int lib_functionA(const char *, int);

Etc.

The code user writes in terms of undecorated function names (lib_functionA), while the header ensures that the correct version suffix is ​​added.

You do not have to change each function; you need to make sure that some function that will always be used will be decorated with the version number. If there is an initialization function ( lib_init()maybe), use it. You can do this with a variable; the hard part then ensures that the variable is specified in each program.

Note that it is more common to ensure that the library interface does not change across versions, so that programs can be linked to any version without compilation.

0

, , , , :

int version_1_1_5=0;

, :

extern int version_1_1_5; //decl
int *p = &version_1_1_5;  // use
+2

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


All Articles