2011-10-04 55 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

相關問題