How to resolve the linker error in C++ compiler

爷,独闯天下 提交于 2020-01-30 10:40:39

问题


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.


回答1:


  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.




回答2:


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



回答3:


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



来源:https://stackoverflow.com/questions/7646318/how-to-resolve-the-linker-error-in-c-compiler

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!