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

发布于 2024-12-08 03:59:37 字数 1815 浏览 0 评论 0原文

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

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

错误:

Undefined symbols for architecture arm:
  "_crypto_alloc", referenced from:
      srtp_stream_clone(srtp_stream_ctx_t const*, unsigned int, srtp_stream_ctx_t**)in libsrtp-arm-apple-darwin9.a(srtp.o)
      srtp_stream_alloc(srtp_stream_ctx_t**, srtp_policy_t const*) in libsrtp-arm-apple-darwin9.a(srtp.o)
      _srtp_create in libsrtp-arm-apple-darwin9.a(srtp.o)
  "_aes_icm_context_init", referenced from:
      srtp_kdf_init(srtp_kdf_t*, unsigned char const*)in libsrtp-arm-apple-darwin9.a(srtp.o)
  "_crypto_kernel_load_debug_module", referenced from:
      _srtp_init in libsrtp-arm-apple-darwin9.a(srtp.o)
  "_rdbx_init", referenced from:
      srtp_stream_init(srtp_stream_ctx_t*, srtp_policy_t const*) in libsrtp-arm-apple-darwin9.a(srtp.o)
      srtp_stream_clone(srtp_stream_ctx_t const*, unsigned int, srtp_stream_ctx_t**)in libsrtp-arm-apple-darwin9.a(srtp.o)
  "_key_limit_clone", referenced from:
      srtp_stream_clone(srtp_stream_ctx_t const*, unsigned int, srtp_stream_ctx_t**)in libsrtp-arm-apple-darwin9.a(srtp.o)
  "_auth_get_tag_length", referenced from:
      _srtp_unprotect_rtcp in libsrtp-arm-apple-darwin9.a(srtp.o)
      _srtp_protect_rtcp in libsrtp-arm-apple-darwin9.a(srtp.o)
      _srtp_unprotect in libsrtp-arm-apple-darwin9.a(srtp.o)
      _srtp_protect in libsrtp-arm-apple-darwin9.a(srtp.o)
...
...

实际上我没有更改makefile中的任何内容。

注意:srtp.c文件中,已经包含了alloc.h文件。我称赞它并编译它。我只得到相同的链接器错误。我从两个方面思考。但我对此不确定。
1. 它没有与 .o 文件链接
2.它不带头文件。 (我对此不太清楚。)

请帮我解决这个问题。

I have to compile PJSIP in CPP compiler. Because I am integrating an API with PJSIP. It is in CPP. So I have to use g++ instead of gcc. But now I didn't integrate any other API.

But I am getting linker error in CPP compiler. If it is C compiler, it is working fine.

Error:

Undefined symbols for architecture arm:
  "_crypto_alloc", referenced from:
      srtp_stream_clone(srtp_stream_ctx_t const*, unsigned int, srtp_stream_ctx_t**)in libsrtp-arm-apple-darwin9.a(srtp.o)
      srtp_stream_alloc(srtp_stream_ctx_t**, srtp_policy_t const*) in libsrtp-arm-apple-darwin9.a(srtp.o)
      _srtp_create in libsrtp-arm-apple-darwin9.a(srtp.o)
  "_aes_icm_context_init", referenced from:
      srtp_kdf_init(srtp_kdf_t*, unsigned char const*)in libsrtp-arm-apple-darwin9.a(srtp.o)
  "_crypto_kernel_load_debug_module", referenced from:
      _srtp_init in libsrtp-arm-apple-darwin9.a(srtp.o)
  "_rdbx_init", referenced from:
      srtp_stream_init(srtp_stream_ctx_t*, srtp_policy_t const*) in libsrtp-arm-apple-darwin9.a(srtp.o)
      srtp_stream_clone(srtp_stream_ctx_t const*, unsigned int, srtp_stream_ctx_t**)in libsrtp-arm-apple-darwin9.a(srtp.o)
  "_key_limit_clone", referenced from:
      srtp_stream_clone(srtp_stream_ctx_t const*, unsigned int, srtp_stream_ctx_t**)in libsrtp-arm-apple-darwin9.a(srtp.o)
  "_auth_get_tag_length", referenced from:
      _srtp_unprotect_rtcp in libsrtp-arm-apple-darwin9.a(srtp.o)
      _srtp_protect_rtcp in libsrtp-arm-apple-darwin9.a(srtp.o)
      _srtp_unprotect in libsrtp-arm-apple-darwin9.a(srtp.o)
      _srtp_protect in libsrtp-arm-apple-darwin9.a(srtp.o)
...
...

Actually I didn't change anything in makefile.

NOTE:
In srtp.c file, already included alloc.h file. I commended it and compiled it. I got the same linker error only. I am thinking in two ways. But I am not sure with this.
1. It is not linking with .o files
2. It is not taking the header files. (I am not clear with this.)

Please help me to resolve this issue.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

离去的眼神 2024-12-15 03:59:37
  1. 不要使用 C++ 编译器编译 C 源代码。只需使用 C 编译器对其进行编译,然后使用 C++ 链接器将其链接到您的 C++ 程序即可。
  2. extern "C" 块中声明所有 C 符号;将您的 #include 指令包装在这样的块中,或者将其放入标头本身中。 (检查标题中是否已经没有这样的块。)

另请参阅 如何混合使用 C 和 C++

  1. Don't compile C source code with a C++ compiler. Just compile it with a C compiler and link it into your C++ program using a C++ linker.
  2. Declare all C symbols in an extern "C" block; either wrap your #include directives in such a block, or put it in the headers themselves. (Check whether there's not such a block in the headers already.)

See also How to mix C and C++ in the C++ FAQ.

來不及說愛妳 2024-12-15 03:59:37

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

处理它的标准方法是用以下内容包装 C 标头:

#ifdef __cplusplus
extern "C" {
#endif

// C declarations here

#ifdef __cplusplus
}
#endif

When C symbols become undefined in a C++ program it means that their declarations are not marked as extern "C".

The standard way to handle it is to wrap C headers with:

#ifdef __cplusplus
extern "C" {
#endif

// C declarations here

#ifdef __cplusplus
}
#endif
何以心动 2024-12-15 03:59:37

这是您的 pjsip 项目中的链接器错误。您使用 xcode 还是其他 IDE 来开发这个项目?

这个错误是因为,上述文件没有成功链接到您的项目。

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

=>>libsrtp-arm-apple-darwin9.a

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

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

It's linker error in your pjsip project. Are you using xcode or anyother IDE to develop this project?

This error is because, the above files are not linked to your project successfully.

Add this below missing library file into your project.

=>>libsrtp-arm-apple-darwin9.a

Follow the below link to link your library file into your project.

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文