如何解决C++编译器中的链接器错误

How to resolve the linker error in C++ compiler

本文关键字:链接 错误 编译器 C++ 何解决 解决      更新时间:2023-10-16

我必须在CPP编译器中编译PJSIP。因为我正在将API与PJSIP进行集成。它在CPP中。所以我必须使用g++而不是gcc。但现在我没有集成任何其他API。

但我在CPP编译器中得到了链接器错误。如果它是C编译器,则工作正常。

错误:

架构臂的未定义符号:"_crypto_alloc",引用自:libsrtp-arm-apple-darwin9.a(srtp.o(中的srtp_stream_clone(srtp_sttream_ctx_t const*,unsigned int,srtp_stream_ctx_t**(libsrtp-arm-apple-darwin9.a(srtp.o(中的srtp_stream_alloc(srtp_sttream_ctx_t**,srtp_policy_t const*(_在libsrtp-arm-apple-darwin9.a中创建srtp_create(srtp.o("_aes_icm_context_init",引用自:libsrtp-arm-apple-darwin9.a(srtp.o(中的srtp_kdf_init(srtp_kdf_t*,无符号字符常量*("_crypto_kernel_load_debug_module",引用自:_libsrtp-arm-apple-darwin9.a中的srtp_init(srtp.o("_rdbx_init",引用自:libsrtp-arm-apple-darwin9.a(srtp.o(中的srtp_stream_init(srtp_sttream_ctx_t*,srtp_policy_t const*(libsrtp-arm-apple-darwin9.a(srtp.o(中的srtp_stream_clone(srtp_sttream_ctx_t const*,unsigned int,srtp_stream_ctx_t**("_key_limit_clone",引用自:libsrtp-arm-apple-darwin9.a(srtp.o(中的srtp_stream_clone(srtp_sttream_ctx_t const*,unsigned int,srtp_stream_ctx_t**("_auth_get_tag_length",引用自:_libsrtp-arm-apple-darwin9.a中的srtp_unprotect_rtcp(srtp.o(_libsrtp-arm-apple-darwin9.a中的srtp_protect_rtcp(srtp.o(_libsrtp-arm-apple-darwin9.a中的srtp_unprotect(srtp.o(_libsrtp-arm-apple-darwin9.a中的srtp_protet(srtp.o(。。。…

事实上,我在makefile中没有更改任何内容。

注意:srtp.c文件中,已经包含了alloc.h文件。我赞扬并编译了它。我只得到了相同的链接器错误。我有两种想法。但我对此并不确定
1.未与.o文件链接
2.它没有获取头文件。(我对此不清楚。(

请帮我解决这个问题。

  1. 不要用C++编译器编译C源代码。只需使用C编译器进行编译,然后使用C++链接器将其链接到您的C++程序中
  2. 声明extern "C"块中的所有C符号;将#include指令封装在这样的块中,或者将其放在头中。(检查标头中是否已经没有这样的块。(

另请参阅C++常见问题解答中的"如何混合使用C和C++"。

C符号在C++程序中未定义时,意味着它们的声明未标记为extern "C"

处理它的标准方法是用包装C标头

#ifdef __cplusplus
extern "C" {
#endif
// C declarations here
#ifdef __cplusplus
}
#endif

这是pjsip项目中的链接器错误。您是否使用xcode或任何其他IDE来开发此项目?

出现此错误的原因是,上述文件未成功链接到您的项目。

将以下缺少的库文件添加到您的项目中。

=>libsrtp-arm-apple-darwin9.a

按照以下链接将库文件链接到项目中。

来源:https://www.chilkatsoft.com/xcode-link-static-lib.asp