Mac M1 openssl CLion 编译问题

问题描述

我有以下任务:编写一个创建 dh 参数的 C/C++ 程序。

我使用 CLion。最初安装的是 OpenSSL,我可以在终端中使用所有 OpenSSL 命令。

MacBook-Air-Nikita ~ % openssl version
LibreSSL 2.8.3

但是,在 CLion 中,我无法添加任何库,因为它看不到它。我使用 Brew 成功安装了新的 OpenSSL;它有这个路径:

/opt/homebrew/Cellar/openssl@1.1/1.1.1i/

但是 CLion 没有看到任何库。所以我将这些行添加到项目 CMakeList.txt 中:

include_directories(/usr/local/Cellar/openssl@1.1/1.1.1i/include/)
set(OPENSSL_ROOT_DIR /usr/local/Cellar/openssl@1.1/1.1.1i/ )
set(OPENSSL_USE_STATIC_LIBS TRUE)
find_package(OpenSSL required)

之后,我可以包含我想要的所有库,但它不起作用。当我尝试使用库中的任何函数运行程序时,构建器失败。

#include <openssl/rand.h>

int main(){
    RAND_bytes(10,10);
    return 0;
}

错误

Undefined symbols for architecture arm64:
  "_RAND_bytes",referenced from:
      _main in main.c.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command Failed with exit code 1 (use -v to see invocation)
make[3]: *** [PV181_HW03] Error 1
make[2]: *** [CMakeFiles/PV181_HW03.dir/all] Error 2
make[1]: *** [CMakeFiles/PV181_HW03.dir/rule] Error 2
make: *** [PV181_HW03] Error 2

有人能告诉我如何解决这个问题吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)