作者:孤l叶_991 | 来源:互联网 | 2023-09-25 14:19
Ikeepgettingld:librarynotfoundfor-lchaiscript_stdlib-5.3.1.soclang:error:linker
I keep getting
LD : librarynotfoundfor-lchaiscript _ stdlib-5.3.1.so
clang : error : linkercommandfailedwithexitcode1(use-vtoseeinvocation )。
When trying to link to a .so
The command I'm using is。
clang main.CPP-ofoo-l.//- lchaiscript _ stdlib-5.3.1.so
What am I doing wrong?
libchaiscript _ stdlib-5.3.1.soisinthesamedirectoryasmain.cppithoughtthe-l./wouldaddthe.sothelibraryseachphpthe
解决方案
yes the-loptionaddsthesearchpath,buttheLinkeraddsthe.so(or.a ) suffixItself ) justlikeitaddsthelibprefix ).soyouonlon
youcanalsoskiptheaddingofthepath,andlinkdirectlywiththefile :
clang main.CPP-ofoolibchaiscript _ stdlib-5.3.1.so
notethattheruntimelinker (whichiswhatactuallyloadsthesharedlibrarieswhenyourunyourprogram )。 mightnotbeabletofindthelibraryifit ' snotintheruntimelinkerspath.youcantellthe (compile time ) linkertoadddapathtothesheshared -。
clang main.CPP-ofoolibchaiscript _ stdlib-5.3.1.so-wl,-rpath,/absolute/path
the-wloptiontellsthecompilerfront-endtopassanoptiontothelinker,andthelinkeroption-rpathaddsapathtotheruntime-linker shelinker