开发者

Why is a Missing Shared Library Fatal?

开发者 https://www.devze.com 2023-03-16 21:38 出处:网络
g++ -o Test Test.cpp -lTest /usr/bin/ld: cannot find -lTest collect2: ld returned 1 exit status If symbols from shared/dynamic libraries are load开发者_开发技巧ed on-demand at runtime, why is it a f
g++ -o Test Test.cpp -lTest
/usr/bin/ld: cannot find -lTest
collect2: ld returned 1 exit status

If symbols from shared/dynamic libraries are load开发者_开发技巧ed on-demand at runtime, why is it a fatal error for a library to be missing at compile-time?


  1. Inter-library dependencies can be difficult to deal with at run time; the compile-time check lets the linker detect and sometimes resolve dependency loops and add any additional library dependencies to the runtime link list.
  2. Would you prefer to find out that you misspelled a symbol name at compile/link time, or at runtime? Most people prefer the former, so the linker checks that all symbols are resolved instead of deferring it to the runtime loader; this of course requires all the libraries to be present.
  3. Suppose a dynamic library requires a static library to be present which otherwise wouldn't be linked in. On most platforms you can't (or can't sanely or safely) load static libraries at runtime, so the linker needs to deal with these at link time. (This is actually a sub-case of #1.)
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号