gpt4 book ai didi

c++ - 与库的 c 绑定(bind)链接

转载 作者:塔克拉玛干 更新时间:2023-11-03 02:02:54 25 4
gpt4 key购买 nike

我正在尝试链接到下一个库:( see docs )

它是一个 C 绑定(bind),用于用 C++ 编写的库。但是如果制作静态库然后尝试链接到它。

我收到这些消息:

uchardet//libuchardet.a(uchardet.cpp.o): In function `uchardet_new':
uchardet.cpp:(.text+0x19): undefined reference to `operator new(unsigned long)'
uchardet.cpp:(.text+0x3c): undefined reference to `std::string::_Rep::_S_empty_rep_storage'
uchardet.cpp:(.text+0x4b): undefined reference to `std::string::assign(char const*, unsigned long)'
uchardet.cpp:(.text+0x6c): undefined reference to `operator delete(void*)'
uchardet.cpp:(.text+0x7f): undefined reference to `std::basic_string<char, std::char_traits<char>, std::allocator<char> >::~basic_string()'
uchardet//libuchardet.a(uchardet.cpp.o): In function `HandleUniversalDetector::Reset()':
uchardet.cpp:(.text._ZN23HandleUniversalDetector5ResetEv[_ZN23HandleUniversalDetector5ResetEv]+0x16): undefined reference to `std::string::assign(char const*, unsigned long)'
uchardet//libuchardet.a(uchardet.cpp.o): In function `HandleUniversalDetector::Report(char const*)':
uchardet.cpp:(.text._ZN23HandleUniversalDetector6ReportEPKc[_ZN23HandleUniversalDetector6ReportEPKc]+0x35): undefined reference to `std::string::assign(char const*, unsigned long)'
uchardet//libuchardet.a(uchardet.cpp.o): In function `HandleUniversalDetector::~HandleUniversalDetector()':
uchardet.cpp:(.text._ZN23HandleUniversalDetectorD2Ev[_ZN23HandleUniversalDetectorD5Ev]+0x1a): undefined reference to `std::string::_Rep::_S_empty_rep_storage'
uchardet.cpp:(.text._ZN23HandleUniversalDetectorD2Ev[_ZN23HandleUniversalDetectorD5Ev]+0x4d): undefined reference to `std::string::_Rep::_M_destroy(std::allocator<char> const&)'
uchardet//libuchardet.a(uchardet.cpp.o): In function `HandleUniversalDetector::~HandleUniversalDetector()':
uchardet.cpp:(.text._ZN23HandleUniversalDetectorD0Ev[_ZN23HandleUniversalDetectorD0Ev]+0x1a): undefined reference to `std::string::_Rep::_S_empty_rep_storage'
uchardet.cpp:(.text._ZN23HandleUniversalDetectorD0Ev[_ZN23HandleUniversalDetectorD0Ev]+0x2c): undefined reference to `operator delete(void*)'
uchardet.cpp:(.text._ZN23HandleUniversalDetectorD0Ev[_ZN23HandleUniversalDetectorD0Ev]+0x55): undefined reference to `std::string::_Rep::_M_destroy(std::allocator<char> const&)'
uchardet//libuchardet.a(uchardet.cpp.o):(.rodata._ZTI23HandleUniversalDetector[_ZTI23HandleUniversalDetector]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(uchardet.cpp.o):(.eh_frame+0xab): undefined reference to `__gxx_personality_v0'
uchardet//libuchardet.a(nsUniversalDetector.cpp.o): In function `nsUniversalDetector::HandleData(char const*, unsigned int)':
nsUniversalDetector.cpp:(.text+0x368): undefined reference to `operator new(unsigned long)'
nsUniversalDetector.cpp:(.text+0x396): undefined reference to `operator new(unsigned long)'
nsUniversalDetector.cpp:(.text+0x3c6): undefined reference to `operator new(unsigned long)'
nsUniversalDetector.cpp:(.text+0x4eb): undefined reference to `operator new(unsigned long)'
nsUniversalDetector.cpp:(.text+0x527): undefined reference to `operator delete(void*)'
nsUniversalDetector.cpp:(.text+0x53a): undefined reference to `operator delete(void*)'
nsUniversalDetector.cpp:(.text+0x554): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsUniversalDetector.cpp.o): In function `nsUniversalDetector::~nsUniversalDetector()':
nsUniversalDetector.cpp:(.text+0x5bc): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsUniversalDetector.cpp.o): In function `nsCharSetProber::~nsCharSetProber()':
nsUniversalDetector.cpp:(.text._ZN15nsCharSetProberD0Ev[_ZN15nsCharSetProberD0Ev]+0x8): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsUniversalDetector.cpp.o):(.rodata._ZTI19nsUniversalDetector[_ZTI19nsUniversalDetector]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
uchardet//libuchardet.a(nsUniversalDetector.cpp.o):(.rodata._ZTV19nsUniversalDetector[_ZTV19nsUniversalDetector]+0x30): undefined reference to `__cxa_pure_virtual'
uchardet//libuchardet.a(nsUniversalDetector.cpp.o):(.rodata._ZTV15nsCharSetProber[_ZTV15nsCharSetProber]+0x20): undefined reference to `__cxa_pure_virtual'
uchardet//libuchardet.a(nsUniversalDetector.cpp.o):(.rodata._ZTV15nsCharSetProber[_ZTV15nsCharSetProber]+0x28): undefined reference to `__cxa_pure_virtual'
uchardet//libuchardet.a(nsUniversalDetector.cpp.o):(.rodata._ZTV15nsCharSetProber[_ZTV15nsCharSetProber]+0x30): undefined reference to `__cxa_pure_virtual'
uchardet//libuchardet.a(nsUniversalDetector.cpp.o):(.rodata._ZTV15nsCharSetProber[_ZTV15nsCharSetProber]+0x38): undefined reference to `__cxa_pure_virtual'
uchardet//libuchardet.a(nsUniversalDetector.cpp.o):(.rodata._ZTV15nsCharSetProber[_ZTV15nsCharSetProber]+0x40): more undefined references to `__cxa_pure_virtual' follow
uchardet//libuchardet.a(nsUniversalDetector.cpp.o):(.rodata._ZTI15nsCharSetProber[_ZTI15nsCharSetProber]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
uchardet//libuchardet.a(nsUniversalDetector.cpp.o):(.eh_frame+0xbb): undefined reference to `__gxx_personality_v0'
uchardet//libuchardet.a(nsEscCharsetProber.cpp.o): In function `nsEscCharSetProber::~nsEscCharSetProber()':
nsEscCharsetProber.cpp:(.text+0x1a0): undefined reference to `operator delete(void*)'
nsEscCharsetProber.cpp:(.text+0x1a9): undefined reference to `operator delete(void*)'
nsEscCharsetProber.cpp:(.text+0x1b2): undefined reference to `operator delete(void*)'
nsEscCharsetProber.cpp:(.text+0x1bb): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsEscCharsetProber.cpp.o): In function `nsEscCharSetProber::~nsEscCharSetProber()':
nsEscCharsetProber.cpp:(.text+0x1e0): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsEscCharsetProber.cpp.o):nsEscCharsetProber.cpp:(.text+0x1e9): more undefined references to `operator delete(void*)' follow
uchardet//libuchardet.a(nsEscCharsetProber.cpp.o): In function `nsEscCharSetProber::nsEscCharSetProber(unsigned int)':
nsEscCharsetProber.cpp:(.text+0x276): undefined reference to `operator new(unsigned long)'
nsEscCharsetProber.cpp:(.text+0x296): undefined reference to `operator new(unsigned long)'
nsEscCharsetProber.cpp:(.text+0x2b6): undefined reference to `operator new(unsigned long)'
nsEscCharsetProber.cpp:(.text+0x2d2): undefined reference to `operator new(unsigned long)'
uchardet//libuchardet.a(nsEscCharsetProber.cpp.o): In function `nsEscCharSetProber::~nsEscCharSetProber()':
nsEscCharsetProber.cpp:(.text+0x20b): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsEscCharsetProber.cpp.o):(.rodata._ZTI18nsEscCharSetProber[_ZTI18nsEscCharSetProber]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(nsEscCharsetProber.cpp.o):(.eh_frame+0x137): undefined reference to `__gxx_personality_v0'
uchardet//libuchardet.a(nsMBCSGroupProber.cpp.o): In function `nsMBCSGroupProber::nsMBCSGroupProber(unsigned int)':
nsMBCSGroupProber.cpp:(.text+0x964): undefined reference to `operator new(unsigned long)'
nsMBCSGroupProber.cpp:(.text+0x97f): undefined reference to `operator new(unsigned long)'
nsMBCSGroupProber.cpp:(.text+0x9d0): undefined reference to `operator new(unsigned long)'
nsMBCSGroupProber.cpp:(.text+0x9f9): undefined reference to `operator new(unsigned long)'
nsMBCSGroupProber.cpp:(.text+0xa22): undefined reference to `operator new(unsigned long)'
uchardet//libuchardet.a(nsMBCSGroupProber.cpp.o):nsMBCSGroupProber.cpp:(.text+0xa43): more undefined references to `operator new(unsigned long)' follow
uchardet//libuchardet.a(nsMBCSGroupProber.cpp.o): In function `nsMBCSGroupProber::nsMBCSGroupProber(unsigned int)':
nsMBCSGroupProber.cpp:(.text+0xd6b): undefined reference to `operator delete(void*)'
nsMBCSGroupProber.cpp:(.text+0xda5): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsMBCSGroupProber.cpp.o): In function `nsMBCSGroupProber::~nsMBCSGroupProber()':
nsMBCSGroupProber.cpp:(.text+0x8f0): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsMBCSGroupProber.cpp.o):(.rodata._ZTI17nsMBCSGroupProber[_ZTI17nsMBCSGroupProber]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(nsMBCSGroupProber.cpp.o):(.rodata._ZTV23JapaneseContextAnalysis[_ZTV23JapaneseContextAnalysis]+0x10): undefined reference to `__cxa_pure_virtual'
uchardet//libuchardet.a(nsMBCSGroupProber.cpp.o):(.rodata._ZTV23JapaneseContextAnalysis[_ZTV23JapaneseContextAnalysis]+0x18): undefined reference to `__cxa_pure_virtual'
uchardet//libuchardet.a(nsMBCSGroupProber.cpp.o):(.rodata._ZTI23JapaneseContextAnalysis[_ZTI23JapaneseContextAnalysis]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
uchardet//libuchardet.a(nsMBCSGroupProber.cpp.o):(.eh_frame+0x67): undefined reference to `__gxx_personality_v0'
uchardet//libuchardet.a(nsSBCSGroupProber.cpp.o): In function `nsSBCSGroupProber::nsSBCSGroupProber()':
nsSBCSGroupProber.cpp:(.text+0xdf4): undefined reference to `operator new(unsigned long)'
nsSBCSGroupProber.cpp:(.text+0xe28): undefined reference to `operator new(unsigned long)'
nsSBCSGroupProber.cpp:(.text+0xe5c): undefined reference to `operator new(unsigned long)'
nsSBCSGroupProber.cpp:(.text+0xe90): undefined reference to `operator new(unsigned long)'
nsSBCSGroupProber.cpp:(.text+0xec4): undefined reference to `operator new(unsigned long)'
uchardet//libuchardet.a(nsSBCSGroupProber.cpp.o):nsSBCSGroupProber.cpp:(.text+0xef8): more undefined references to `operator new(unsigned long)' follow
uchardet//libuchardet.a(nsSBCSGroupProber.cpp.o): In function `nsSBCSGroupProber::nsSBCSGroupProber()':
nsSBCSGroupProber.cpp:(.text+0x13fb): undefined reference to `operator delete(void*)'
nsSBCSGroupProber.cpp:(.text+0x1422): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsSBCSGroupProber.cpp.o): In function `nsSBCSGroupProber::~nsSBCSGroupProber()':
nsSBCSGroupProber.cpp:(.text+0xdc9): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsSBCSGroupProber.cpp.o):(.rodata._ZTI17nsSBCSGroupProber[_ZTI17nsSBCSGroupProber]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(nsSBCSGroupProber.cpp.o):(.eh_frame+0x67): undefined reference to `__gxx_personality_v0'
uchardet//libuchardet.a(nsSBCharSetProber.cpp.o): In function `nsSingleByteCharSetProber::~nsSingleByteCharSetProber()':
nsSBCharSetProber.cpp:(.text._ZN25nsSingleByteCharSetProberD0Ev[_ZN25nsSingleByteCharSetProberD0Ev]+0x8): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsSBCharSetProber.cpp.o):(.rodata._ZTI25nsSingleByteCharSetProber[_ZTI25nsSingleByteCharSetProber]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(nsSJISProber.cpp.o): In function `nsSJISProber::~nsSJISProber()':
nsSJISProber.cpp:(.text._ZN12nsSJISProberD2Ev[_ZN12nsSJISProberD5Ev]+0x10): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsSJISProber.cpp.o): In function `nsSJISProber::~nsSJISProber()':
nsSJISProber.cpp:(.text._ZN12nsSJISProberD0Ev[_ZN12nsSJISProberD0Ev]+0x10): undefined reference to `operator delete(void*)'
nsSJISProber.cpp:(.text._ZN12nsSJISProberD0Ev[_ZN12nsSJISProberD0Ev]+0x20): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsSJISProber.cpp.o):(.rodata._ZTI12nsSJISProber[_ZTI12nsSJISProber]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(nsUTF8Prober.cpp.o): In function `nsUTF8Prober::~nsUTF8Prober()':
nsUTF8Prober.cpp:(.text._ZN12nsUTF8ProberD2Ev[_ZN12nsUTF8ProberD5Ev]+0x10): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsUTF8Prober.cpp.o): In function `nsUTF8Prober::~nsUTF8Prober()':
nsUTF8Prober.cpp:(.text._ZN12nsUTF8ProberD0Ev[_ZN12nsUTF8ProberD0Ev]+0x10): undefined reference to `operator delete(void*)'
nsUTF8Prober.cpp:(.text._ZN12nsUTF8ProberD0Ev[_ZN12nsUTF8ProberD0Ev]+0x20): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsUTF8Prober.cpp.o):(.rodata._ZTI12nsUTF8Prober[_ZTI12nsUTF8Prober]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(nsLatin1Prober.cpp.o): In function `nsLatin1Prober::~nsLatin1Prober()':
nsLatin1Prober.cpp:(.text._ZN14nsLatin1ProberD0Ev[_ZN14nsLatin1ProberD0Ev]+0x8): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsLatin1Prober.cpp.o):(.rodata._ZTI14nsLatin1Prober[_ZTI14nsLatin1Prober]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(CharDistribution.cpp.o):(.rodata._ZTI24CharDistributionAnalysis[_ZTI24CharDistributionAnalysis]+0x0): undefined reference to `vtable for __cxxabiv1::__class_type_info'
uchardet//libuchardet.a(CharDistribution.cpp.o):(.rodata._ZTI25EUCTWDistributionAnalysis[_ZTI25EUCTWDistributionAnalysis]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(CharDistribution.cpp.o):(.rodata._ZTI25EUCKRDistributionAnalysis[_ZTI25EUCKRDistributionAnalysis]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(CharDistribution.cpp.o):(.rodata._ZTI26GB2312DistributionAnalysis[_ZTI26GB2312DistributionAnalysis]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(CharDistribution.cpp.o):(.rodata._ZTI24Big5DistributionAnalysis[_ZTI24Big5DistributionAnalysis]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(CharDistribution.cpp.o):(.rodata._ZTI24SJISDistributionAnalysis[_ZTI24SJISDistributionAnalysis]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(CharDistribution.cpp.o):(.rodata._ZTI25EUCJPDistributionAnalysis[_ZTI25EUCJPDistributionAnalysis]+0x0): more undefined references to `vtable for __cxxabiv1::__si_class_type_info' follow
uchardet//libuchardet.a(nsHebrewProber.cpp.o): In function `nsHebrewProber::~nsHebrewProber()':
nsHebrewProber.cpp:(.text._ZN14nsHebrewProberD0Ev[_ZN14nsHebrewProberD0Ev]+0x8): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsHebrewProber.cpp.o):(.rodata._ZTI14nsHebrewProber[_ZTI14nsHebrewProber]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(nsBig5Prober.cpp.o): In function `nsBig5Prober::~nsBig5Prober()':
nsBig5Prober.cpp:(.text._ZN12nsBig5ProberD2Ev[_ZN12nsBig5ProberD5Ev]+0x10): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsBig5Prober.cpp.o): In function `nsBig5Prober::~nsBig5Prober()':
nsBig5Prober.cpp:(.text._ZN12nsBig5ProberD0Ev[_ZN12nsBig5ProberD0Ev]+0x10): undefined reference to `operator delete(void*)'
nsBig5Prober.cpp:(.text._ZN12nsBig5ProberD0Ev[_ZN12nsBig5ProberD0Ev]+0x20): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsBig5Prober.cpp.o):(.rodata._ZTI12nsBig5Prober[_ZTI12nsBig5Prober]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(nsEUCJPProber.cpp.o): In function `nsEUCJPProber::~nsEUCJPProber()':
nsEUCJPProber.cpp:(.text._ZN13nsEUCJPProberD2Ev[_ZN13nsEUCJPProberD5Ev]+0x10): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsEUCJPProber.cpp.o): In function `nsEUCJPProber::~nsEUCJPProber()':
nsEUCJPProber.cpp:(.text._ZN13nsEUCJPProberD0Ev[_ZN13nsEUCJPProberD0Ev]+0x10): undefined reference to `operator delete(void*)'
nsEUCJPProber.cpp:(.text._ZN13nsEUCJPProberD0Ev[_ZN13nsEUCJPProberD0Ev]+0x20): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsEUCJPProber.cpp.o):(.rodata._ZTI13nsEUCJPProber[_ZTI13nsEUCJPProber]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(nsEUCKRProber.cpp.o): In function `nsEUCKRProber::~nsEUCKRProber()':
nsEUCKRProber.cpp:(.text._ZN13nsEUCKRProberD2Ev[_ZN13nsEUCKRProberD5Ev]+0x10): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsEUCKRProber.cpp.o): In function `nsEUCKRProber::~nsEUCKRProber()':
nsEUCKRProber.cpp:(.text._ZN13nsEUCKRProberD0Ev[_ZN13nsEUCKRProberD0Ev]+0x10): undefined reference to `operator delete(void*)'
nsEUCKRProber.cpp:(.text._ZN13nsEUCKRProberD0Ev[_ZN13nsEUCKRProberD0Ev]+0x20): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsEUCKRProber.cpp.o):(.rodata._ZTI13nsEUCKRProber[_ZTI13nsEUCKRProber]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(nsEUCTWProber.cpp.o): In function `nsEUCTWProber::~nsEUCTWProber()':
nsEUCTWProber.cpp:(.text._ZN13nsEUCTWProberD2Ev[_ZN13nsEUCTWProberD5Ev]+0x10): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsEUCTWProber.cpp.o): In function `nsEUCTWProber::~nsEUCTWProber()':
nsEUCTWProber.cpp:(.text._ZN13nsEUCTWProberD0Ev[_ZN13nsEUCTWProberD0Ev]+0x10): undefined reference to `operator delete(void*)'
nsEUCTWProber.cpp:(.text._ZN13nsEUCTWProberD0Ev[_ZN13nsEUCTWProberD0Ev]+0x20): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsEUCTWProber.cpp.o):(.rodata._ZTI13nsEUCTWProber[_ZTI13nsEUCTWProber]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
uchardet//libuchardet.a(nsGB2312Prober.cpp.o): In function `nsGB18030Prober::~nsGB18030Prober()':
nsGB2312Prober.cpp:(.text._ZN15nsGB18030ProberD2Ev[_ZN15nsGB18030ProberD5Ev]+0x10): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsGB2312Prober.cpp.o): In function `nsGB18030Prober::~nsGB18030Prober()':
nsGB2312Prober.cpp:(.text._ZN15nsGB18030ProberD0Ev[_ZN15nsGB18030ProberD0Ev]+0x10): undefined reference to `operator delete(void*)'
nsGB2312Prober.cpp:(.text._ZN15nsGB18030ProberD0Ev[_ZN15nsGB18030ProberD0Ev]+0x20): undefined reference to `operator delete(void*)'
uchardet//libuchardet.a(nsGB2312Prober.cpp.o):(.rodata._ZTI15nsGB18030Prober[_ZTI15nsGB18030Prober]+0x0): undefined reference to `vtable for __cxxabiv1::__si_class_type_info'
collect2: error: ld returned 1 exit status

如果 make shared one 并尝试在我的程序中使用它,它会编译,但是当我运行它时,我有:

error while loading shared libraries: libuchardet.so.0: cannot open shared object file: No such file or directory

我是这样编译的:

gcc test.c  -Ithird -Lthird/parserutils/lib_amd64/ -lparserutils -I uchardet/ -L uchardet/ -luchardet

好的!这行得通!

LD_LIBRARY_PATH=uchardet/ ./a.out

但是我可以在这里使用静态链接吗?

最佳答案

对于共享库案例:默认情况下,RTLD 仅应用公共(public)库搜索路径。要添加另一个,请在链接二进制文件时添加一个选项:-Wl,-rpath=$libdir,例如


gcc test.c -Ithird -Lthird/parserutils/lib_amd64/ -lparserutils -I uchardet/ -L uchardet/ -luchardet -Wl,-rpath=`pwd`/uchardet

此选项将要求 RTLD 也在指定目录中搜​​索库。可以为此处调用的每个附加目录指定多次。

静态库情况发生了什么,您可以确定对共享库使用 ldd。它很可能需要 libg++、libstdc++ 或模拟,具体取决于您的系统。如果是这样,您还应该为您的链接添加其静态模拟。即使编译了纯 C 代码,g++ 也会自动执行此操作,但 gcc 不会。

关于c++ - 与库的 c 绑定(bind)链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20731614/

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