lua - Symbol not found: OpenSSL_version_num
问题描述
I am trying to create a kong plugin. It works great when running as part of kong server but when I am trying to write some unit tests with busted, resty.openssl.digest
func load fails. More specifically while loading the version.lua
I am not sure what exactly I am missing. Maybe some link which is supposed to link openSSL's C functions to lua.
Here is a minimal snippet to reproduce the problem.
package.cpath = package.cpath .. ';/usr/local/lib/lua/5.1/?.so'
local ffi = require("ffi")
ffi.cdef[[
// 1.0
unsigned long SSLeay(void);
const char *SSLeay_version(int t);
// >= 1.1
unsigned long OpenSSL_version_num();
const char *OpenSSL_version(int t);
// >= 3.0
const char *OPENSSL_info(int t);
// BoringSSL
int BORINGSSL_self_test(void);
]]
local num = ffi.C.OpenSSL_version_num()
print(num)
Error:
luajit: test.lua:18: Symbol not found: OpenSSL_version_num
stack traceback:
[C]: in function '__index'
test.lua:18: in main chunk
[C]: at 0x55b71c78ffa4
解决方案
You should ffi.load
your .so library before using functions from it.
local ffi = require("ffi")
ffi.cdef"long SSLeay(void);" -- I have ver 1.0
ffi.load("ssl", true)
print(ffi.C.SSLeay()) --> 268439887LL
Note:
package.cpath
is used only for require()
.
It does not affect FFI functions.
推荐阅读
- r - 使用 data.table 按聚合值设置子集
- c++ - C ++如何检查程序是否第一次运行?
- javascript - 调用 tbody 的 td child 设置类名
- machine-learning - 用于分类的多个不同大小的特征集
- excel - 带图片的 Excel 下拉列表
- python-3.x - 如何在 Python 中创建变量引用列表?
- mysql - 在 MySQL 的 Where 子句中使用 Join 和 Select 语句需要帮助
- api - 使用 API 的 Paypal 自动付款
- react-native - 用于反应原生图像选择器的 useEffect
- r - 比较 dplyr 中的字符串