简体   繁体   English

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

[英]How to resolve the linker error in C++ compiler

I have to compile PJSIP in CPP compiler. 我必须在CPP编译器中编译PJSIP Because I am integrating an API with PJSIP . 因为我正在将API与PJSIP集成PJSIP It is in CPP . CPP So I have to use g++ instead of gcc . 所以我必须使用g++而不是gcc But now I didn't integrate any other API. 但是现在我没有集成任何其他API。

But I am getting linker error in CPP compiler. 但是我在CPP编译器中收到链接器错误。 If it is C compiler, it is working fine. 如果是C编译器,则工作正常。

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 . 实际上,我没有更改makefile任何内容。

NOTE: In srtp.c file, already included alloc.h file. 注:srtp.c文件中,已经包含alloc.h文件。 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 1.它没有与.o文件链接
2. It is not taking the header files. 2.它不使用头文件。 (I am not clear with this.) (我不清楚。)

Please help me to resolve this issue. 请帮助我解决此问题。

When C symbols become undefined in a C++ program it means that their declarations are not marked as extern "C" . C符号在C++程序中变得未定义时,这意味着它们的声明未标记为extern "C"

The standard way to handle it is to wrap C headers with: 处理它的标准方法是使用以下命令包装C标头:

#ifdef __cplusplus
extern "C" {
#endif

// C declarations here

#ifdef __cplusplus
}
#endif
  1. Don't compile C source code with a C++ compiler. 不要使用C ++编译器来编译C源代码。 Just compile it with a C compiler and link it into your C++ program using a C++ linker. 只需使用C编译器进行编译,然后使用C ++链接器将其链接到C ++程序中即可。
  2. Declare all C symbols in an extern "C" block; extern "C"块中声明所有C符号; either wrap your #include directives in such a block, or put it in the headers themselves. 将您的#include指令包装在这样的块中,或将其放在标头中。 (Check whether there's not such a block in the headers already.) (检查标题中是否已经没有这样的块。)

See also How to mix C and C++ in the C++ FAQ. 另请参阅C ++常见问题解答中的如何混合使用C和C ++

It's linker error in your pjsip project. 这是您的pjsip项目中的链接器错误。 Are you using xcode or anyother IDE to develop this project? 您是否正在使用xcode或任何其他IDE开发此项目?

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 = >> libsrtp - 臂 - 苹果darwin9.a

Follow the below link to link your library file into your project. 单击下面的链接将您的库文件链接到您的项目。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM