के खोज आदेश के बारे में कुछ प्रश्न मेरे पास जीसीसी लिंक ऑर्डर के बारे में कुछ प्रश्न हैं। जीसीसी मैन डिफ़ॉल्ट रूप से बार-बार खोज किए बिना बाएं से दाएं लिंकर खोज प्रतीकों का कहना है। यहाँ मेरी परीक्षा है:जीसीसी लिंकर
main.c
#include <stdio.h>
#include <stdlib.h>
int main()
{
printf("HELLO WROLD\n");
return 0;
}
printf.c
#include <stdio.h>
#include <stdlib.h>
int printf(const char *fmt, ...)
{
write(1, "AAA\n", 4);
}
[[email protected] testcode]# gcc -c -fno-builtin-printf *.c
[[email protected] testcode]# gcc -o test main.o printf.o
[[email protected] testcode]# ./test
AAA
[[email protected] testcode]# gcc -o test printf.o main.o
[[email protected] testcode]# ./test
AAA
[[email protected] testcode]# ar rcs libprintf.a printf.o
[[email protected] testcode]# gcc -o test libprintf.a main.o
[[email protected] testcode]# ./test
HELLO WROLD
[[email protected] testcode]# gcc -o test main.o libprintf.a
[[email protected] testcode]# ./test
AAA
[[email protected] testcode]# gcc -shared -o libprintf.so printf.o
[[email protected] testcode]# gcc -o test libprintf.so main.o
[[email protected] testcode]# export LD_LIBRARY_PATH=.
[[email protected] testcode]# ./test
AAA
[[email protected] testcode]# gcc -o test main.o libprintf.so
[[email protected] testcode]# ./test
AAA
परिणाम से, हम ओ और ओ, ओ और के आदेश देख सकते हैं .so कोई फर्क नहीं पड़ता, केवल .o और .a का ऑर्डर प्रभाव पड़ता है। लेकिन यह जीसीसी मैन पेज के साथ असंगत है। तो क्यों?
मैंने -v का उपयोग किया है, लेकिन फिर भी मुझे समझ में नहीं आता क्यों। क्या आप इसे विस्तार से समझा सकते हैं? – D3Hunter
मैं -nodefaultlibs का उपयोग नहीं कर सकता, क्योंकि crst में कुछ फ़ंक्शंस जैसे _start मौजूद होना चाहिए। – D3Hunter
मुझे लगता है कि मैं टीएल; डीआर-एड पहले। आपको लगता है कि 'यह' जीसीसी एमएन पृष्ठ के साथ असंगत है? – sehe