【问题标题】:Add openssl library into my project, got errors 'openssl/ossl_typ.h' file not found将 openssl 库添加到我的项目中,出现错误 'openssl/ossl_typ.h' file not found
【发布时间】:2017-07-19 18:05:52
【问题描述】:

我安装了 openssl-1.1.0f 并将库添加到我的源代码中。

myProject (Folder)
- myApp (Folder)
  - myApp.c
- openssl-1.1.0f (Folder)

在我的源代码 myApp.c 中,我在下面添加了:

#include "../openssl-1.1.0f/include/openssl/rand.h"
#include "../openssl-1.1.0f/include/openssl/ssl.h"

然后我编译了。

gcc -Wall -Wextra -Werror -static -o myApp myApp.c -L../openssl/openssl-1.1.0f/ -lssl -lcrypto -I../openssl/openssl-1.1.0f/include

我得到了错误。

../../openssl-1.1.0f/include/openssl/rand.h:14:11 fatal error 'openssl/ossl_typ.h' file not found

但是openssl-1.1.0f/include/openssl中有ossl_typ.h文件。

我该如何解决这个问题?

【问题讨论】:

  • 您必须运行Configure 来生成一些特定于安装的文件。你这样做了吗?
  • 我做到了——按照安装指南进行配置、制作和安装。而且我没有更改“openssl-1.1.0f”文件夹中的任何内容。

标签: c openssl


【解决方案1】:

您包含错误的文件。您需要使用-I 选项告诉编译器openssl 的包含文件在哪里。

目前您告诉它查看“../openssl/openssl-1.1.0f/include/”这是错误的,因为该文件夹不存在。根据文件夹布局,它应该是“-I../openssl-1.1.0f/include/”。当您包含文件时,您无需指定完整路径,因为编译器将能够看到它们。

#include "openssl/rand.h"
#include "openssl/ssl.h"

在这些文件中,它包含“openssl/ossl_typ.h”,如果你告诉它正确的位置,它现在就能找到它。

【讨论】:

  • 这是我下载并安装的“openssl-1.1.0f”文件夹。我不想更改 openssl 开源文件夹。
  • 您没有更改文件夹,而是将正确的路径放入其中。我已经更改了答案,希望能更清楚?
【解决方案2】:

我认为你能做的最好的事情是,openssl-1.1.0f 包使用include 目录来添加

CFLAGS += "-I<pathToOpenSSlParentDir>/openssl-1.1.0f/include"

到你的Makefile,然后

...
#include <openssl/rand.h>
#include <openssl/ssl.h>
...

在您要编译的文件中。或者您可以更好地在系统中默认安装您的 openssl,然后一切都会按预期工作。

我最后一段的原因是,如果你将 openssl 编译为共享库,那么你必须添加 LD_LIBRARY_PATH=${LD_LIBRARY_PATH}:&lt;pathToOpenSSlParentDir&gt;/openssl-1.1.0f/build 或类似的东西,以便运行时能够在运行时找到它们。您可以避免强制使用静态链接进行链接的问题,但代价是更大的可执行文件和运行时在内存中加载的多个库实例。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-01
    • 2011-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-22
    • 2013-10-14
    • 1970-01-01
    相关资源
    最近更新 更多