How do I compile a binary which works with both libcrypto.so.0.9.8 and libcryto.so.1.0.0?

StackOverflow https://stackoverflow.com/questions/16088261

  •  04-04-2022
  •  | 
  •  

문제

I have an autotools C project.

How do I compile a binary which works with both libcrypto.so.0.9.8 and libcryto.so.1.0.0? (i.e. Ubuntu 9.10 and 12.04)

Depending on the age of the OS on which I do the build, the binary requires one version or the other.

Is there a way of making it not care, or are the differences between the libcryto versions insurmountable?

도움이 되었습니까?

해결책

In my opinion, you want to use some function of libcrypto.so.0.9.8 and some from libcryto.so.1.0.0. If most of the functions are required from 1.0.0 or is preferred choice then link with libcrypto.so.1.0.0.

And you may need some function from libcrypto.so.0.9.8 or you may have other good reasons to use libcrypto.so.0.9.8.

In my view, if you link from both the library, you will get linker error (duplicate symbols as both of the library contains same symbols).

If you need to use 0.9.8, then load it dynamically using dlopen and get the function callback which you want use with dlsym.

This can be accomplished as follows:

void * handle;
/*reqd_callback is the callback of required function.*/
reqd_callback cb;

handle = dlopen ("libcrypto.so.0.9.8", RTLD_LAZY);
cb     = (reqd_callback)dlsym(handle, "reqd_function");
//Call the cb
cb (parameters);

//Close the library.
dlclose(handle);

I think this may solve your purpose. If the preference is inverse, invert the library in linking and in loading through program.

다른 팁

Can you make a soft link that will "point" to either libcrypto.so.0.9.8 or libcryto.so.1.0.0. Give it a generic name and then use that, then whatever version of the library the link "points" to, will be picked up? On app install, you set your soft link to point to the library version available. Your software might be tested up to 1.0.0 if the lib is backward compatible enough, i.e. you don't rely on somthing in 1.0.0 that's not in 0.9.8, your ok.

You can rebuild ssl-0.9.8 (not 1.x because it contains some things that won't work on the older version) and change the line in the makefile where it does the final shared library linkage and embeds the SONAME

recompile it with the SONAME changed from libssl.so.0.9.8 to libssl.so.0

it will look something like: -Wl,-soname,libssl.so.0.9.8 change it to: -Wl,-soname,libssl.so.0

now when you compile against this library the binaries built against it will look for libssl.so.0 (which is included as a symlink in both versions)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top