最近项目用到了一个c++的功能库,出现大量报错,c++调用c,中间遇到很多问题,现在把解决过程列出来,可能问题有些低略,有需要的看下吧,废话不多说了下面列出问题和解决方法
问题一:编译报错
flv_tag_creator.cpp:(.text+0x646): undefined reference to `operator new(unsigned int)'
flv_tag_creator.cpp:(.text+0x6bc): undefined reference to `operator delete(void*)'
flv_tag_creator.cpp:(.text+0x6dc): undefined reference to `__cxa_end_cleanup'
../lib//libmuxflv.a(flv_tag_creator.o): In function `FLVTagCreator::createVideoTag(unsigned char*, unsigned int, unsigned int)':
flv_tag_creator.cpp:(.text+0x796): undefined reference to `operator new(unsigned int)'
flv_tag_creator.cpp:(.text+0x80c): undefined reference to `operator delete(void*)'
flv_tag_creator.cpp:(.text+0x82c): undefined reference to `__cxa_end_cleanup'
../lib//libmuxflv.a(flv_tag_creator.o): In function `FLVTagCreator::createAudioTag(unsigned char, unsigned char*, unsigned int, unsigned int)':
flv_tag_creator.cpp:(.text+0x8ee): undefined reference to `operator new(unsigned int)'
flv_tag_creator.cpp:(.text+0x964): undefined reference to `operator delete(void*)'
flv_tag_creator.cpp:(.text+0x984): undefined reference to `__cxa_end_cleanup'
../lib//libmuxflv.a(flv_tag_creator.o): In function `__static_initialization_and_destruction_0(int, int)':
flv_tag_creator.cpp:(.text+0x9b2): undefined reference to `std::ios_base::Init::Init()'
flv_tag_creator.cpp:(.text+0x9be): undefined reference to `std::ios_base::Init::~Init()'
flv_tag_creator.cpp:(.text+0x9c2): undefined reference to `std::ios_base::Init::~Init()'
../lib//libmuxflv.a(flv_tag_creator.o):(.ARM.extab+0x18): undefined reference to `__gxx_personality_v0'
../lib//libmuxflv.a(flv_tag_creator.o):(.ARM.extab+0x40): undefined reference to `__gxx_personality_v0'
../lib//libmuxflv.a(flv_tag_creator.o):(.ARM.extab+0x68): undefined reference to `__gxx_personality_v0'
../lib//libmuxflv.a(flv_tag_creator.o):(.ARM.extab+0x90): undefined reference to `__gxx_personality_v0'
../lib//libmuxflv.a(flv_tag_creator.o): In function `std::__shared_count<(__gnu_cxx::_Lock_policy)2>::__shared_count<FLVTag*>(FLVTag*)':
flv_tag_creator.cpp:(.text._ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC2IP6FLVTagEET_[_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC5IP6FLVTagEET_]+0x12): undefined reference to `operator new(unsigned int)'
flv_tag_creator.cpp:(.text._ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC2IP6FLVTagEET_[_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC5IP6FLVTagEET_]+0x28): undefined reference to `__cxa_end_catch'
flv_tag_creator.cpp:(.text._ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC2IP6FLVTagEET_[_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC5IP6FLVTagEET_]+0x2c): undefined reference to `__cxa_end_cleanup'
flv_tag_creator.cpp:(.text._ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC2IP6FLVTagEET_[_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC5IP6FLVTagEET_]+0x34): undefined reference to `__cxa_begin_catch'
flv_tag_creator.cpp:(.text._ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC2IP6FLVTagEET_[_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC5IP6FLVTagEET_]+0x4a): undefined reference to `__cxa_rethrow'
../lib//libmuxflv.a(flv_tag_creator.o):(.ARM.extab.text._ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC2IP6FLVTagEET_[_ZNSt14__shared_countILN9__gnu_cxx12_Lock_policyE2EEC5IP6FLVTagEET_]+0x0): undefined reference to `__gxx_personality_v0'
../lib//libmuxflv.a(flv_tag_creator.o): In function `std::_Sp_counted_ptr<FLVTag*, (__gnu_cxx::_Lock_policy)2>::~_Sp_counted_ptr()':
flv_tag_creator.cpp:(.text._ZNSt15_Sp_counted_ptrIP6FLVTagLN9__gnu_cxx12_Lock_policyE2EED2Ev[_ZNSt15_Sp_counted_ptrIP6FLVTagLN9__gnu_cxx12_Lock_policyE2EED5Ev]+0x1e): undefined reference to `operator delete(void*)'
../lib//libmuxflv.a(flv_tag_creator.o): In function `std::_Sp_counted_ptr<FLVTag*, (__gnu_cxx::_Lock_policy)2>::~_Sp_counted_ptr()':
flv_tag_creator.cpp:(.text._ZNSt15_Sp_counted_ptrIP6FLVTagLN9__gnu_cxx12_Lock_policyE2EED0Ev[_ZNSt15_Sp_counted_ptrIP6FLVTagLN9__gnu_cxx12_Lock_policyE2EED0Ev]+0x10): undefined reference to `operator delete(void*)'
../lib//libmuxflv.a(flv_tag_creator.o):(.rodata._ZTISt15_Sp_counted_ptrIP6FLVTagLN9__gnu_cxx12_Lock_policyE2EE[_ZTISt15_Sp_counted_ptrIP6FLVTagLN9__gnu_cxx12_Lock_policyE2EE]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
../lib//libmuxflv.a(flv_tag.o): In function `FLVTag::~FLVTag()':
flv_tag.cpp:(.text+0x348): undefined reference to `operator delete(void*)'
../lib//libmuxflv.a(flv_tag.o): In function `FLVTag::~FLVTag()':
flv_tag.cpp:(.text+0x36c): undefined reference to `operator delete(void*)'
../lib//libmuxflv.a(flv_tag.o): In function `__static_initialization_and_destruction_0(int, int)':
flv_tag.cpp:(.text+0x47a): undefined reference to `std::ios_base::Init::Init()'
flv_tag.cpp:(.text+0x486): undefined reference to `std::ios_base::Init::~Init()'
flv_tag.cpp:(.text+0x48a): undefined reference to `std::ios_base::Init::~Init()'
../lib//libmuxflv.a(flv_tag.o): In function `.LC0':
flv_tag.cpp:(.rodata+0x28): undefined reference to `vtable for __cxxabiv1::__class_type_info'
collect2: error: ld returned 1 exit status
make[1]: *** [jzipc] Error 1
make[1]: Leaving directory `/home/lilei/TUTK_IPC_SJC9144TU/bak/branch/develop/hi3511-dvs-src/LINUX'
make: *** [313e] Error 2
解决方法:
makefile使用gcc -lstdc++ -std=c++11
因为我使用到了c++11的方法,没用到的自行去掉
问题二:编译找不到class
解决方法在class前面加入
#ifdef __cplusplus
#endif
c调用的部分加入
#ifdef __cplusplus
extern "C"{
#endif /* _cplusplus */
#ifdef __cplusplus
}
#endif /* _cplusplus *