如何解决在C ++编译器的链接器错误 [英] How to resolve the linker error in C++ compiler
问题描述
我要编译 PJSIP
在 CPP
编译器。因为我与整合的API PJSIP
。它是在 CPP
。所以,我必须使用 G ++
而不是 GCC
。但现在我没有集成任何其他的API。
但我得到的 CPP
编译链接错误。如果是 C
编译器,它工作正常。
错误:
针对ARM架构的未定义符号:
_crypto_alloc,从引用:
srtp_stream_clone(srtp_stream_ctx_t const的*,无符号整型,srtp_stream_ctx_t **)在libsrtp臂 - 苹果darwin9.a(srtp.o)
在libsrtp臂 - 苹果darwin9.a(srtp.o)srtp_stream_alloc(srtp_stream_ctx_t **,srtp_policy_t常量*)
在libsrtp臂 - 苹果darwin9.a(srtp.o)_srtp_create
_aes_icm_context_init,从引用:
srtp_kdf_init(srtp_kdf_t *,无符号的字符常量*)在libsrtp臂 - 苹果darwin9.a(srtp.o)
_crypto_kernel_load_debug_module,从引用:
在libsrtp臂 - 苹果darwin9.a(srtp.o)_srtp_init
_rdbx_init,从引用:
srtp_stream_init(srtp_stream_ctx_t *,srtp_policy_t常量*)在libsrtp臂 - 苹果darwin9.a(srtp.o)
srtp_stream_clone(srtp_stream_ctx_t const的*,无符号整型,srtp_stream_ctx_t **)在libsrtp臂 - 苹果darwin9.a(srtp.o)
_key_limit_clone,从引用:
srtp_stream_clone(srtp_stream_ctx_t const的*,无符号整型,srtp_stream_ctx_t **)在libsrtp臂 - 苹果darwin9.a(srtp.o)
_auth_get_tag_length,从引用:
在libsrtp臂 - 苹果darwin9.a(srtp.o)_srtp_unprotect_rtcp
在libsrtp臂 - 苹果darwin9.a(srtp.o)_srtp_protect_rtcp
在libsrtp臂 - 苹果darwin9.a(srtp.o)_srtp_unprotect
在libsrtp臂 - 苹果darwin9.a(srtp.o)_srtp_protect
...
...
其实我并没有改变任何东西生成文件
。
注意:
在 srtp.c
文件中,已经包含了 alloc.h
文件。我赞扬它,它编译。我只得到了同样的连接错误。我想在两个方面。但我不知道这一点。结果
1.不与的.o
文件链接结果
2.未服用的头文件。 (我不是随本清。)
请帮我解决这个问题。
- 请不要编译C源代码code与C ++编译器。只需用C语言编译器编译并使用C ++链接器将其链接到你的C ++程序。
- 声明所有的C符号在
的externC
块;无论是包裹在这样一个块你的的#include
指令,或把它放在自己的头。 (检查是否有不已经是头这样的块。)
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.
- 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.
- 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.
这篇关于如何解决在C ++编译器的链接器错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!