编译 c 和 c++ 模块
Compiling c and c++ module
假设我正在开发一个已经存在的自由开关模块(https://github.com/signalwire/freeswitch(。它们是动态加载的。
我过去创建过模块,这不是我的问题。我的问题来自一个已经存在的模块,我们称之为my_module。在本模块中,我将添加一个新功能,我需要解密在 AES 中加密的 jwt 令牌参数。
现有的模块主文件,由主 freeSWITCH 加载器加载的文件是 C 语言,我们这样说:
#include <switch.h>
#include <switch_json.h>
#include <switch_stun.h>
#include <jwt.h>
#include "token_crypto.h" <-- This is my addition
...
<some stuff goes here>
在某些时候,我会这样做:
plaintext_len = token_decrypt( *token_encoded, plaintext );
我的token_crypto.h 是
SWITCH_BEGIN_EXTERN_C
#include <stdio.h>
#include <string.h>
#include <openssl/ssl.h>
#include <openssl/evp.h>
#include <openssl/err.h>
#include <openssl/bio.h>
#include <openssl/buffer.h>
#include <openssl/sha.h>
void handleErrors(unsigned char *ciphertext);
int gcm_decrypt(unsigned char *ciphertext, int ciphertext_len,
unsigned char *aad, int aad_len,
unsigned char *tag,
unsigned char *key,
unsigned char *iv, int iv_len,
unsigned char *plaintext);
int token_decrypt( const char token_encoded, unsigned char *plaintext );
SWITCH_END_EXTERN_C
然后实际实现token_crypto.cpp
我在 Makefile.am 中添加了编译token_crypto的要求,如下所示:
mod_mymodule_la_SOURCES =
base64url.cpp
token_crypto.cpp
mod_mymodule.c
然后代码编译正常,但是当我尝试加载它时,我得到:
**/usr/local/freeswitch/mod/mod_mymodule.so: undefined symbol: token_decrypt**
我知道链接器找不到编译的引用,但我只是不知道如何链接它们......
可以在此处找到示例生成文件 https://github.com/signalwire/freeswitch/blob/master/src/mod/applications/mod_skel/Makefile.am
也许我应该指出,在该.c文件上还有其他cpp源代码。
我知道通过使用"extern c"编译器不会破坏函数名称......但是,就实际使用 C 源文件中的函数而言,这意味着什么?
像"谷歌这个","谷歌那个"这样的评论是没有帮助的。在来这里之前,我显然做了所有这些,所以...
所以,显然使用"extern c"包含头文件是不够的......出于某种原因,这就是我记得的。
如果一个人不"extern c"实际的cpp实现,那么功能将被破坏。将"extern C"添加到实现中对我有用。
无论如何,谢谢大家。
- 尝试导入pybind-opencv模块时出现libgtk错误
- 为什么当我解模块化时,这个C++代代码"效率较低"?
- 如果C++对象的类在另一个boost模块中声明,如何使用boost将指向该对象的指针返回到python
- 内联如何影响模块接口中的成员函数
- C++返回 Numpy 数组的 Python 扩展模块
- 当我尝试加载内核模块时,如何修复C++中的这个 malloc() 错误?
- 如何从线程中的不同模块调用函数?
- 如何使用 soong 命名空间来有条件地编译模块
- asn1c 不会从 asn.1 模块中提取八位字节字符串的默认值
- CMake - 模块 + 库混淆
- 特征 LLT 模块给出不正确的结果?
- 枚举进程模块在有效句柄上返回无效句柄
- 在 python 模块中导入子模块时PyImport_Import失败
- 将 PCL 链接到 Cython C++ 模块
- 即使直接从官方示例中复制,也找不到未知类型名称QML_ELEMENT和 QML 模块
- 电源功能模块化操作
- 如何告诉本机节点模块所需的dll存储在哪里?
- 如何为模块化应用程序实现C++插件系统
- C++ Python 模块在 Blender 中崩溃,但在 Python 控制台中不会崩溃
- Arduino 模块化编程与全局和设置