1. 程式人生 > >庫檔案存,ld報錯找不到

庫檔案存,ld報錯找不到

專案中遇到一個問題,庫是已經編譯好的庫,用-L選項,編譯缺提示找不到庫檔案,如下:

not found (try using -rpath or -rpath-link)
在網路上找到答案,感謝萬能的google:
When you see the following kind of errors during cross compilation (linking phase):
ld: warning: libfontconfig.so.1, needed by …/libQtGui.so, not found (try using -rpath or -rpath-link)
ld: warning: libaudio.so.2, needed by …/libQtGui.so, not found (try using -rpath or -rpath-link)
There could be two reasons:
  • the list of required binaries is not complete and linker cannot complete the linking automatically
  • your $SYSROOT/usr/lib is not passed to linker by -rpath-link as mentioned in error message
During normal native build your libraries are stored in standard locations (/usr/lib) and locating libraries is easier. Cross compilation needs more attention in this ares as SYSROOT is not standard. Then search for LDFLAGS setup in your build scripts: LDFLAGS="-L${STAGING_LIBDIR}" And change to the following: LDFLAGS="-Wl,-rpath-link,${STAGING_LIBDIR}
-L${STAGING_LIBDIR}" The clumsy syntax -Wl,<options-with-comma-as-space> tells your compiler (that is used for linking purposes) to pass the options (with commas replaced by spaces of course) to linker (ld).