c++調用c的問題處理

最近項目用到了一個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 *

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章