2012-04-01 59 views
3

gcc(g ++)鏈接器是否支持一個選項,以便在某些給定的庫無法找到時不會失敗? 謝謝, 拉菲爲gcc鏈接器指定可選庫

+1

會是什麼的呢? – Mat 2012-04-01 12:59:52

+0

除了失敗之外,它還能做什麼? – 2012-04-01 13:00:48

+0

歡迎來到Stack Overflow。我時不時遇到這個問題。 – 2012-04-01 13:08:22

回答

0

這聽起來像你想要的是這個從LD手冊頁:

--allow-shlib-undefined 
--no-allow-shlib-undefined 
Allows or disallows undefined symbols in shared libraries. This switch is similar to --no-undefined except that it determines the behaviour when the undefined symbols are in a shared library rather than a regular object file. It does not affect how undefined symbols in regular object files are handled. 

The default behaviour is to report errors for any undefined symbols referenced in shared libraries if the linker is being used to create an executable, but to allow them if the linker is being used to create a shared library. 

The reasons for allowing undefined symbol references in shared libraries specified at link time are that: 
• A shared library specified at link time may not be the same as the one that is available at load time, so the symbol might actually be resolvable at load time. 

• There are some operating systems, eg BeOS and HPPA , where undefined symbols in shared libraries are normal. 
The BeOS kernel for example patches shared libraries at load time to select whichever function is most appropriate for the current architecture. This is used, for example, to dynamically select an appropriate memset function.