且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何检查是否安装了OpenSSL或cryptopp并用实际系统中存在的库(已安装)?

更新时间:2023-09-11 15:47:40

这不是那么简单。为了找到一个宏被定义,则必须包括定义该宏头。而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.