如何检查是否安装了OpenSSL或cryptopp并用实际系统中存在的库(已安装)? [英] How to check if openssl or cryptopp is installed and use the library that actually exists in the system (is installed)?

查看:2030
本文介绍了如何检查是否安装了OpenSSL或cryptopp并用实际系统中存在的库(已安装)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的函数,加密/解密的缓冲区(相同功能的2个版本 - 先用cryptopp,第二 - 与OpenSSL的)。

I wrote function that encrypts/decrypts a buffer (2 versions of the same function - first, with cryptopp, second - with openssl).

我想作这样的事:

#if defined OPENSSL
   run_aes_openssl(...);
#elif defined CRYPTOPP
   run_aes_crytopp(...);
#else
    error(...);
#end

这可能吗?

推荐答案

这不是那么简单。为了找到一个宏被定义,则必须包括定义该宏头。而C没有像包括了foo.h当且仅当它存在任何东西;它拥有否则存在有一个编译错误。

It's not quite that simple. In order to find that a macro is defined, you have to include the header that defines that macro. And C doesn't have anything like "include foo.h iff it exists"; it has to exist otherwise there is a compilation error.

通常这会通过你编译之前运行的脚本进行清理整顿。你的脚本检查如位置/ usr / include目录的/ usr /本地/包括等等,看是否OpenSSL的头都在那里。然后输出包含在CFLAGS -DHAVE_OPENSSL 一个Makefile。那么你的code可以检查该宏。

Normally this would be sorted out by a script that you run before compilation. Your script checks locations like /usr/include, /usr/local/include, etc., to see if the OpenSSL headers are there; and then it outputs a Makefile which contains in the CFLAGS -DHAVE_OPENSSL. Then your code can check for that macro.

这是相当多的喧嚣,让事情变得简单,你可能需要用户手动编辑文件,例如利用所谓的分发项目 user_config.h 用户应该在编译之前进行编辑,以指定他们把OpenSSL和等。

This is quite a bit of hullabaloo, to keep things simple you could require the user to manually edit a file , e.g. distribute your project with something called user_config.h that the user is supposed to edit before compiling, to specify where they put OpenSSL and so on.

有一个叫做GNU的Autoconf preset的系统,该系统包含一个脚本来检查你的系统在阳光下的一切。这有其优点和缺点;它使得更容易为平民们下载源$ C ​​$ C的东西,但它是bloaty并可以为自己努力工作。

There is a preset system called GNU Autoconf which contains a script that checks your system for everything under the sun. This has its advantages and disadvantages; it makes things easier for plebs downloading your source code, but it is bloaty and can be hard work for yourself.

这篇关于如何检查是否安装了OpenSSL或cryptopp并用实际系统中存在的库(已安装)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆