अधिक अनुसंधान के बाद, मुझे एहसास हुआ कि सामान किस तरह काम करता है। साझा पुस्तकालयों के अपरिभाषित प्रतीकों में हेरफेर करने के लिए दो लिंकर विकल्प हैं:
पहला वाला --no-undefined
है। यह अनसुलझे प्रतीकों की रिपोर्ट करता है जिन्हें चरणबद्ध करने पर तत्काल हल नहीं किया जाता है। जब तक कि लिंक साझा की गई साझा लाइब्रेरी में नहीं मिलता है, या तो मैन्युअल रूप से (-l
स्विच के साथ) या स्वचालित रूप से (libgcc_s
, सी ++ रनटाइम; libc
, सी रनटाइम; ld-linux-**.so
, डायनामिक लिंकर यूटिल) उठाया गया है, --no-undefined
इसे त्रुटि के रूप में रिपोर्ट करता है। प्रश्नकर्ता की यही कुंजी है।
एक और कुंजी है, --no-allow-shlib-undefined
(जिसका वर्णन --no-undefined
भी सुझाता है)। यह जांचता है कि साझा पुस्तकालयों में परिभाषा जो आप अपनी साझा लाइब्रेरी को से लिंक करते हैं, संतुष्ट हैं। इस विषय में दिखाए गए मामले में यह कुंजी थोड़ा उपयोग नहीं है, लेकिन यह उपयोगी हो सकती है।हालांकि, इसकी अपनी बाधाएं हैं।
--allow-shlib-undefined
--no-allow-shlib-undefined
Allows (the default) or disallows undefined symbols in shared
libraries (It is meant, in shared libraries _linked_against_, not the
one we're creating!--Pavel Shved). This switch is similar to --no-un-
defined 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 reason that --allow-shlib-undefined is the default is that the
shared library being specified at link time may not be the same as
the one that is available at load time, so the symbols might actually
be resolvable at load time. Plus there are some systems, (eg BeOS)
where undefined symbols in shared libraries is normal. (The kernel
patches them at load time to select which function is most appropri-
ate for the current architecture. This is used for example to dynam-
ically select an appropriate memset function). Apparently it is also
normal for HPPA shared libraries to have undefined symbols.
बात यह है कि क्या इसके बाद के संस्करण कहा जाता है भी सच है, उदाहरण के लिए, लिनक्स सिस्टम के लिए है, जहां के आंतरिक दिनचर्या में से कुछ साझा है:
मैनपेज के बारे में क्यों यह डिफ़ॉल्ट नहीं कर रहा है कुछ औचित्य प्रदान करता है पुस्तकालय ld-linux.so
में कार्यान्वित किया गया है, गतिशील लोडर (यह निष्पादन योग्य और साझा लाइब्रेरी दोनों है)। जब तक आप किसी भी तरह से लिंक है, तो आप कुछ इस तरह मिल जाएगा:
/lib64/libc.so.6: undefined reference to `[email protected]_PRIVATE'
/lib64/libc.so.6: undefined reference to `[email protected]_PRIVATE'
/usr/lib64/gcc/x86_64-suse-linux/4.3/libstdc++.so: undefined reference to `[email protected]_2.3'
/lib64/libc.so.6: undefined reference to `[email protected]_PRIVATE'
/lib64/libc.so.6: undefined reference to `[email protected]_PRIVATE'
ये लोडर, ld-linux.so
से अपरिभाषित संदर्भ हैं। यह मंच-विशिष्ट है (उदाहरण के लिए, मेरे सिस्टम पर सही लोडर /lib64/ld-linux-x86-64.so
है)। the Mandriva wiki पर
g++ -fPIC -shared -o liba.so a.o -Wl,--no-allow-shlib-undefined /lib64/ld-linux-x86-64.so.2
नहीं, बिल्कुल कोई त्रुटि नहीं। –
क्या आप लिंकर आउटपुट प्रदान कर सकते हैं? –
एचएम, मैंने शपथ ली थी कि मैंने पहले ऐसा किया था और आउटपुट के रूप में कुछ भी नहीं मिला। ऐसा करने के लिए फिर से यह काम ठीक लग रहा था (यानी मुझे एक त्रुटि मिलती है!) –