gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 06:41:27 26 4
gpt4 key购买 nike

我必须在CPP 编译器中编译PJSIP。因为我正在将 API 与 PJSIP 集成。它在 CPP 中。所以我必须使用 g++ 而不是 gcc。但是现在我没有集成任何其他 API。

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

请帮我解决这个问题。

最佳答案

  1. 不要使用 C++ 编译器编译 C 源代码。只需使用 C 编译器编译它,然后使用 C++ 链接器将其链接到您的 C++ 程序。
  2. extern "C" block 中声明所有 C 符号;要么将您的 #include 指令包装在这样的 block 中,要么将其放在 header 中。 (检查标题中是否已经没有这样的 block 。)

另见 How to mix C and C++在 C++ 常见问题解答中。

关于c++ - 如何解决 C++ 编译器中的链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7646318/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com