假设我正在使用一个已经存在的freeswitch模块(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中找到一个样例Makefile
也许我应该指出,在.c文件中还使用了其他cpp源代码文件。
我知道通过使用"extern c“,编译器不会破坏函数名……但是,就实际使用c源文件中的函数而言,这意味着什么?
像“谷歌这个”,“谷歌那个”这样的评论是没有帮助的。很明显我在来这之前就做了这些,所以...
发布于 2020-06-14 18:53:52
显然,使用"extern c“的include头文件是不够的。不知怎么的,这就是我记得的。
如果没有将c“extern”到实际的cpp实现中,那么函数将会被破坏。将"extern C“添加到实现中对我来说很有效。
无论如何,谢谢大家。
https://stackoverflow.com/questions/62367016
复制相似问题