2011-10-04 57 views
0

我要编译PJSIP编译器CPP。因为我正在将API与PJSIP集成。它在CPP。所以我必须使用g++而不是gcc。但是现在我没有集成任何其他API。如何解决C++编译器中的链接器错误

但我在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.它没有取头文件。 (我不清楚这个。)

请帮我解决这个问题。

+2

顺便说一下,'CPP'意味着C预处理器。 'C++'表示C + plus。 –

+1

你是否清楚“编译”和“链接”之间的区别,并且C++不能编译C和C不能编译C++,但是如果一个链接器在单独调用和之后调用,C++可以导出到C? –

+0

我们可以用C编译器编译C++编译器和C++代码。但事情是;如果您在C++代码中使用命名空间等,则无法使用C编译器编译C++代码。 – jfalexvijay

回答

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

另请参阅How to mix C and C++的C++ FAQ。

+0

关于'1.':如果C代码调用回C++并且C++代码抛出异常,您可能想用C++编译器编译C代码。这不会使C代码对异常安全,但是,至少可以传播异常而不会导致应用程序崩溃。 –

+0

@MaximYegorushkin:用C++编译器原样编译C代码可能会引起语言间非常微妙的语义差异。我一直在他们旁边,我不会向任何人推荐它。 –

+0

其实我打算从C文件中调用CPP函数。 CPP不支持C功能。那就是问题所在。 – jfalexvijay

1

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

来处理它的标准方法是包裹C头与:

#ifdef __cplusplus 
extern "C" { 
#endif 

// C declarations here 

#ifdef __cplusplus 
} 
#endif 
+0

我做了同样的事情。但是我遇到了同样的问题。 – jfalexvijay

0

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

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

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

= >> libsrtp臂,苹果darwin9.a

按照下面的链接到你的库文件链接到您的项目。

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

相关问题