PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Compilation Process in C: Preprocessing, Compiling, Assembling, Linking (C प्रोग्राम का संकलन चक्र: प्रीप्रोसेसर, कंपाइलर, असेंबलर, लिंकर) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।
Overview: Transforming a C source file (app.c) into a native executable requires four sequential translation stages: Preprocessing (.i), Compiling (.s), Assembling (.o/.obj), and Linking (.out/.exe). Knowing each stage's GCC flags (-E, -S, -c), intermediate artifacts, and error types (syntax vs undefined reference) is essential for multi-file builds and IT competitive exams.
अध्याय सार: किसी C सोर्स कोड (app.c) को नेटिव निष्पादन योग्य फाइल में बदलने के लिए चार क्रमिक चरण होते हैं: प्रीप्रोसेसिंग (.i), कंपाइलिंग (.s), असेंबलिंग (.o/.obj) और लिंकिंग (.out/.exe)। प्रत्येक चरण के GCC फ्लैग्स (-E, -S, -c), मध्यवर्ती फाइल प्रारूप तथा त्रुटियों (Syntax Error बनाम Linker Error) की पहचान मल्टी-फाइल प्रोग्रामिंग व परीक्षाओं के लिए अत्यंत आवश्यक है।
Compilation Process in C: Preprocessing, Compiling, Assembling, Linking: Detailed Notes & Architecture (C प्रोग्राम का संकलन चक्र: प्रीप्रोसेसर, कंपाइलर, असेंबलर, लिंकर)
1. Stage 1: Preprocessing (gcc -E -> .i Expanded Source) (चरण 1: प्रीप्रोसेसिंग (gcc -E -> .i विस्तारित सोर्स))
[EN] The C Preprocessor (cpp) operates purely at the text level before any C grammar rules are checked. Invoked with 'gcc -E app.c -o app.i', it strips all /* */ and // comments, recursively pastes every #include header file inline, performs textual #define macro expansion, and evaluates conditional compilation directives (#if, #ifdef, #ifndef). Because standard headers like <stdio.h> expand fully inside it, the resulting .i file remains valid C code—often spanning hundreds or thousands of lines.
[HI] प्रीप्रोसेसर (cpp) C ग्रामर की जांच से पहले शुद्ध टेक्स्ट स्तर पर कार्य करता है। 'gcc -E' चलाने पर यह सभी कमेंट्स हटा देता है, #include की गई संपूर्ण हेडर फाइल्स को कोड में चिपका देता है, #define मैक्रोज़ का विस्तार करता है तथा #ifdef जैसी शर्तों को हल करता है। इससे उत्पन्न .i फाइल अभी भी शुद्ध C कोड ही होती है।
2. Stage 2: Compilation (gcc -S -> .s Assembly Code) (चरण 2: संकलन / कंपाइलिंग (gcc -S -> .s असेंबली कोड))
[EN] The Compiler core (cc1) takes the expanded .i file and executes lexical analysis (tokenizing), syntax parsing (building an Abstract Syntax Tree), semantic/type checking, intermediate representation optimization, and code generation. Every syntax error—missing semicolons, mismatched braces, undeclared variables, and incompatible types—is caught in this stage. Running 'gcc -S app.i -o app.s' stops right here, producing a human-readable .s file containing target CPU assembly instructions (such as x86-64 or ARM mnemonics).
[HI] कंपाइलर कोर (cc1) विस्तारित .i फाइल पर लेक्सिकल, सिंटैक्स व सिमैंटिक विश्लेषण करके मध्यवर्ती कोड को ऑप्टिमाइज करता है। सेमीकोलन छूटने, अघोषित वेरिएबल या टाइप त्रुटि जैसे सभी सिंटैक्स एरर इसी चरण में पकड़े जाते हैं। 'gcc -S' द्वारा प्राप्त आउटपुट .s फाइल लक्षित CPU की मानव-पठनीय असेंबली भाषा होती है।
3. Stage 3: Assembling (gcc -c -> .o / .obj Relocatable Object) (चरण 3: असेंबलिंग (gcc -c -> .o / .obj ऑब्जेक्ट फाइल))
[EN] The Assembler (as) translates assembly mnemonics from .s into binary machine opcodes via 'gcc -c app.s -o app.o', producing a Relocatable Object File (.o in ELF on Linux, .obj in COFF on Windows). Crucially, calls to external functions like printf() cannot yet be resolved to concrete memory addresses, so the assembler records unresolved external names in a symbol and relocation table inside the .o file. Because an object file lacks C runtime startup linkage and resolved external addresses, the OS cannot execute .o directly.
[HI] असेंबलर (as) .s फाइल के असेंबली निर्देशों को बाइनरी मशीन ऑपकोड में बदलकर रीलोकेटेबल ऑब्जेक्ट फाइल (.o या .obj) बनाता है। चूँकि printf() जैसे बाहरी फंक्शन्स के अंतिम पते अभी अज्ञात रहते हैं, इसलिए असेंबलर उन्हें सिंबल व रीलोकेशन टेबल में अपूर्ण (Unresolved) रखता है। इसी कारण .o फाइल को सीधे रन नहीं किया जा सकता।
4. Stage 4: Linking (ld -> Executable) & Static vs Dynamic Libraries (चरण 4: लिंकिंग (ld -> एक्जीक्यूटेबल) और स्टैटिक बनाम डायनामिक लिंकिंग)
[EN] The Linker (ld) merges all user .o files, C runtime startup objects (crt1.o), and referenced libraries (libc, libm) to resolve external symbols, assign virtual section addresses (.text, .data, .bss), and emit the final executable (a.out or app.exe). Calling a prototyped function whose body does not exist anywhere triggers a Linker Error ('undefined reference to foo'), whereas two files defining the same non-static global cause a 'multiple definition' error. Static linking (-static, .a/.lib) embeds library code inside the binary (bigger, self-contained), while dynamic linking (.so/.dll) loads shared libraries at runtime (smaller executable, shared RAM).
[HI] लिंकर (ld) सभी .o फाइलों, CRT स्टार्टअप ऑब्जेक्ट और मानक/बाहरी लाइब्रेरीज को जोड़कर हर बाहरी सिंबल के वास्तविक मेमोरी पते तय करता है और अंतिम निष्पादनीय फाइल (.out/.exe) बनाता है। प्रोटोटाइप होने पर भी फंक्शन की परिभाषा न मिलने पर लिंकर 'undefined reference' त्रुटि देता है। स्टैटिक लिंकिंग (.a/.lib) लाइब्रेरी कोड को फाइल में ही जोड़ देती है, जबकि डायनामिक लिंकिंग (.so/.dll) रनटाइम पर साझा लाइब्रेरी लोड करती है।
Syntax, Formula & Technical Example (Compilation Process in C: Preprocessing, Compiling, Assembling, Linking)
# Step-by-step C Compilation Pipeline using GCC:
gcc -E main.c -o main.i # 1. Preprocessor: macro/header expansion -> .i
gcc -S main.i -o main.s # 2. Compiler: syntax check & codegen -> .s
gcc -c main.s -o main.o # 3. Assembler: machine opcodes (reloc) -> .o
gcc main.o -o main # 4. Linker: resolve CRT + libc -> ELF/EXE
gcc -save-temps main.c # Single command preserving .i, .s, and .o files
Compilation Process in C: Preprocessing, Compiling, Assembling, Linking Quick Reference & Comparison Table
| Compilation Stage | GCC Flag & Input -> Output | Primary Action & Error Type |
|---|---|---|
| 1. Preprocessing (cpp) | gcc -E : .c -> .i (expanded C text) | Removes comments; expands #include and #define macros |
| 2. Compiling (cc1) | gcc -S : .i -> .s (assembly mnemonics) | AST parsing & type check; catches missing ';' syntax errors |
| 3. Assembling (as) | gcc -c : .s -> .o / .obj (relocatable object) | Generates machine opcodes & unresolved symbol table |
| 4. Linking (ld) | gcc .o -> a.out / app.exe (executable) | Binds CRT & libraries; catches undefined/multiple symbols |
Compilation Process in C: Preprocessing, Compiling, Assembling, Linking Top 20 Bilingual MCQs with Answers
Q1. What is the correct chronological order of the four C compilation stages?
(C प्रोग्राम के संकलन की चार अवस्थाओं का सही कालानुक्रमिक क्रम क्या है?)
(A) Preprocessing -> Compiling -> Assembling -> Linking
(B) Assembling -> Preprocessing -> Compiling -> Linking
(C) Compiling -> Preprocessing -> Linking -> Assembling
(D) Linking -> Compiling -> Assembling -> Preprocessing
Correct Answer: (A)
[EN] C code first undergoes text preprocessing (.i), then compiles to assembly (.s), assembles into object opcodes (.o), and finally links into an executable.
[HI] पहले प्रीप्रोसेसिंग (.i), फिर कंपाइलिंग (.s), उसके बाद असेंबलिंग (.o) और अंत में लिंकिंग से एक्जीक्यूटेबल बनता है।
Q2. Which GCC command stops immediately after Preprocessing and writes expanded C source code to main.i?
(कौन सा GCC कमांड केवल प्रीप्रोसेसिंग तक रुककर विस्तारित C कोड को main.i में सेव करता है?)
(A) gcc -Wall main.c -o main.i
(B) gcc -S main.c -o main.i
(C) gcc -c main.c -o main.i
(D) gcc -E main.c -o main.i
Correct Answer: (D)
[EN] The -E flag executes only the C preprocessor (cpp); -S stops at assembly (.s) and -c stops at object code (.o).
[HI] -E फ्लैग केवल प्रीप्रोसेसर चलाकर .i आउटपुट देता है; -S असेंबली तक और -c ऑब्जेक्ट फाइल तक रुकता है।
Q3. What kind of content is inside the .s file produced by 'gcc -S main.c'?
('gcc -S main.c' से बनने वाली .s फाइल के भीतर किस प्रकार का कोड होता है?)
(A) Preprocessed C code with comments preserved
(B) Java Virtual Machine bytecode
(C) Pure raw binary machine opcodes only
(D) Target CPU Assembly language instructions (human-readable text)
Correct Answer: (D)
[EN] The C compiler emits architecture-specific assembly instructions (.s) before the assembler converts them to binary opcodes.
[HI] -S विकल्प द्वारा कंपाइलर लक्षित प्रोसेसर की मानव-पठनीय असेंबली भाषा (.s) उत्पन्न करता है।
Q4. Why can an operating system NOT directly run a .o (or .obj) file generated by 'gcc -c main.c'?
('gcc -c main.c' से बनी .o (या .obj) ऑब्जेक्ट फाइल को ऑपरेटिंग सिस्टम सीधे निष्पादित क्यों नहीं कर सकता?)
(A) It still contains unexpanded #include directives
(B) It lacks CRT startup linkage and still has unresolved external symbol addresses (like printf)
(C) Object files are compressed ZIP archives
(D) It is written in plain ASCII English text
Correct Answer: (B)
[EN] A .o file is relocatable object code requiring the linker (ld) to assign final virtual addresses and connect library code.
[HI] .o फाइल में CRT स्टार्टअप कोड और printf जैसे बाहरी फंक्शन्स के पते अनसुलझे होते हैं, जिन्हें लिंकर पूरा करता है।
Q5. Suppose file.c declares 'void greet(void);', calls 'greet();' inside main(), and NEVER defines greet() anywhere. Which command succeeds and which fails?
(यदि file.c में 'void greet(void);' का प्रोटोटाइप और कॉल हो पर उसकी परिभाषा कहीं न हो, तो कौन सा कमांड सफल होगा और कौन सा विफल?)
(A) Both gcc -c and gcc -o fail during Preprocessing
(B) gcc -E file.c FAILS with a syntax error
(C) gcc -S file.c FAILS with an undefined reference error
(D) gcc -c file.c SUCCEEDS (produces file.o), while gcc file.c -o app FAILS at Linking
Correct Answer: (D)
[EN] Compilation (-c) only checks that greet's call matches its prototype; only the Linker checks that greet's machine body actually exists.
[HI] ऑब्जेक्ट फाइल बनने (-c) तक प्रोटोटाइप ही काफी होता है; परिभाषा न मिलने की त्रुटि ('undefined reference') अंतिम लिंकिंग चरण में आती है।
Q6. In which stage of C build pipeline is a missing semicolon (;) or mismatched data type detected?
(C प्रोग्राम में सेमीकोलन (;) छूटने या गलत डेटा टाइप की त्रुटि किस चरण में पकड़ी जाती है?)
(A) Compiling stage (cc1 parser/semantic analyzer)
(B) Linking stage (ld)
(C) Preprocessing stage (cpp)
(D) Assembling stage (as)
Correct Answer: (A)
[EN] Syntax parsing and type checking occur inside the compiler stage (.i -> .s), not in the text preprocessor or linker.
[HI] लेक्सिकल, सिंटैक्स और टाइप जांच कंपाइलिंग चरण (.i -> .s) में होती है, प्रीप्रोसेसर या लिंकर में नहीं।
Q7. If two separate files a.c and b.c both define a non-static global variable 'int counter = 0;', what error occurs when linking them together?
(यदि दो अलग फाइलों a.c और b.c में गैर-स्टैटिक ग्लोबल 'int counter = 0;' परिभाषित हो, तो उन्हें साथ जोड़ने पर कौन सी त्रुटि आएगी?)
(A) Preprocessor error: header loop
(B) Linker error: multiple definition of 'counter'
(C) Syntax error during gcc -c a.c
(D) Runtime division by zero
Correct Answer: (B)
[EN] Each file compiles fine alone with -c, but when ld combines a.o and b.o, two global definitions collide under the One Definition Rule.
[HI] अलग-अलग -c करने पर त्रुटि नहीं आती, पर लिंकर जब दोनों .o फाइलें मिलाता है तो 'multiple definition' एरर देता है।
Q8. Which standard GCC command-line flag compiles source files up to object code (.o) WITHOUT invoking the linker?
(GCC का कौन सा फ्लैग लिंकर को चलाए बिना केवल ऑब्जेक्ट कोड (.o) बनाकर रुक जाता है?)
(A) -c
(B) -o
(C) -E
(D) -S
Correct Answer: (A)
[EN] -c compiles and assembles each .c into a .o object file so large multi-file projects can recompile only changed files.
[HI] -c फ्लैग कोड को ऑब्जेक्ट फाइल (.o) तक संकलित करता है और लिंकिंग स्टेज को छोड़ देता है।
Q9. What is a key difference between Static Linking (.a / .lib) and Dynamic Linking (.so / .dll)?
(स्टैटिक लिंकिंग (.a / .lib) और डायनामिक लिंकिंग (.so / .dll) के बीच मुख्य अंतर क्या है?)
(A) Static linking copies library code inside the executable (larger, standalone); dynamic linking loads shared libraries at runtime
(B) Dynamic linking runs only inside the preprocessor
(C) Static linking fails unless internet access is active
(D) Dynamic linking eliminates all .o files during compilation
Correct Answer: (A)
[EN] Static executables carry their own copy of library functions, whereas dynamic binaries share one library image in RAM across processes.
[HI] स्टैटिक लिंकिंग लाइब्रेरी कोड को बाइनरी में ही कॉपी कर देती है, जबकि डायनामिक लिंकिंग रनटाइम पर साझा लाइब्रेरी लोड करती है।
Q10. On Linux GCC, why does using 'double y = sqrt(x);' with a non-constant variable x often fail linking unless '-lm' is added?
(Linux GCC में वैरिएबल x के साथ 'sqrt(x)' उपयोग करने पर प्रायः '-lm' फ्लैग लगाए बिना लिंकिंग विफल क्यों हो जाती है?)
(A) Math functions reside in libm (separate from standard libc), so the linker needs -lm to locate sqrt
(B) <math.h> is a C++ header not valid in C
(C) -lm enables macro preprocessing
(D) sqrt() is executed by the assembler
Correct Answer: (A)
[EN] #include <math.h> only provides the function declaration (prototype); the compiled math body lives in libm.so/libm.a.
[HI] <math.h> केवल प्रोटोटाइप देता है, जबकि sqrt का वास्तविक मशीन कोड अलग मैथ लाइब्रेरी (libm) में होता है जिसे -lm से जोड़ा जाता है।
Q11. What does the GCC option '-save-temps' accomplish when compiling a single file?
(किसी फाइल को कंपाइल करते समय GCC का '-save-temps' विकल्प क्या करता है?)
(A) It stores temporary variables inside CPU registers
(B) It deletes all source .c files after linking
(C) It forces static linking of libc
(D) It preserves the intermediate .i, .s, and .o files alongside the final executable
Correct Answer: (D)
[EN] Normally GCC stores .i, .s, and .o in temporary OS folders and deletes them; -save-temps writes them in the working directory for inspection.
[HI] सामान्यतः GCC मध्यवर्ती .i, .s व .o फाइलों को मिटा देता है; -save-temps उन्हें जांचने के लिए सुरक्षित रख लेता है।
Q12. Inside a compiled ELF object or executable, which memory segment holds uninitialized global and static variables (zero-filled)?
(कंपाइल की गई ELF ऑब्जेक्ट या एक्जीक्यूटेबल फाइल के किस सेगमेंट में अन-इनिशियलाइज्ड ग्लोबल व स्टैटिक वेरिएबल्स रहते हैं?)
(A) .rodata
(B) .bss (Block Started by Symbol)
(C) .stack
(D) .text
Correct Answer: (B)
[EN] .text holds machine instructions, .data holds initialized non-zero globals, and .bss reserves space for zero-initialized globals without bloating disk size.
[HI] .text में मशीन कोड, .data में इनिशियलाइज्ड ग्लोबल तथा .bss में शून्य-आधारित अन-इनिशियलाइज्ड ग्लोबल/स्टैटिक वेरिएबल रहते हैं।
Q13. What filename does GCC generate by default on Linux/Unix if you run 'gcc hello.c' without specifying '-o'?
(यदि Linux/Unix पर '-o' दिए बिना केवल 'gcc hello.c' चलाया जाए, तो डिफ़ॉल्ट आउटपुट फाइल का नाम क्या बनता है?)
(A) hello.o
(B) main.bin
(C) hello.exe
(D) a.out
Correct Answer: (D)
[EN] Historically named 'assembler output' from Ken Thompson's PDP-7 UNIX, GCC still defaults output binaries on POSIX systems to a.out.
[HI] ऐतिहासिक रूप से 'assembler output' के नाम पर POSIX सिस्टम्स में डिफ़ॉल्ट एक्जीक्यूटेबल फाइल a.out बनती है।
Q14. In which compilation stage are #ifdef conditional branches evaluated and comments stripped?
(कोड से कमेंट्स हटाने और #ifdef कंडीशनल ब्रांचेस का मूल्यांकन करने का कार्य किस चरण में होता है?)
(A) Preprocessing
(B) Dynamic Runtime Loading
(C) Assembling
(D) Compiling
Correct Answer: (A)
[EN] Both comment stripping and #if/#ifdef conditional inclusion happen in the preprocessor before the compiler ever sees tokens.
[HI] कमेंट्स हटाना और #ifdef जैसी प्रीप्रोसेसर शर्तों को हल करना संकलन से पहले प्रीप्रोसेसिंग चरण में होता है।
Q15. In multi-file C projects (like Make builds), why do developers compile each .c file with '-c' into .o files first before linking?
(मल्टी-फाइल C प्रोजेक्ट्स (जैसे Make बिल्ड) में पहले हर .c को '-c' से .o में बदलकर फिर लिंकिंग क्यों की जाती है?)
(A) Because .o files execute faster than final executables
(B) Because -c removes all runtime errors automatically
(C) Because GCC cannot accept more than one .c file at once
(D) Incremental builds: editing one .c file requires recompiling only that .o file instead of all source files
Correct Answer: (D)
[EN] Separating compilation (-c) from linking saves massive build time when only one module changes.
[HI] यदि एक ही .c फाइल में बदलाव हो तो केवल उसी की .o फाइल दोबारा बनानी पड़ती है और बाकी .o को सीधे लिंक कर लिया जाता है।
Q16. Which statement about the C compilation pipeline is FALSE?
(C संकलन प्रक्रिया (Compilation Pipeline) के बारे में निम्नलिखित में से कौन सा कथन असत्य (FALSE) है?)
(A) The Compiler translates .i source into architecture-specific .s assembly
(B) The Linker combines object files and runtime startup code into an executable
(C) The Preprocessor validates variable data types and resolves external library functions like printf()
(D) The Assembler outputs a relocatable .o object file
Correct Answer: (C)
[EN] The preprocessor knows nothing about C data types or library addresses; type checking happens in the Compiler and library binding in the Linker.
[HI] प्रीप्रोसेसर केवल टेक्स्ट बदलाव करता है; उसे डेटा टाइप्स की जांच या printf() जैसी लाइब्रेरी के पते जोड़ने का ज्ञान नहीं होता।
Q17. Within Compilation Process in C: Preprocessing, Compiling, Assembling, Linking, which compilation stage directly maps to: "gcc -E : .c -> .i (expanded C text)"?
(Compilation Process in C: Preprocessing, Compiling, Assembling, Linking में कौन सा Compilation Stage सीधे "gcc -E : .c -> .i (expanded C text)" से संबंधित है?)
(A) 1. Preprocessing (cpp)
(B) 4. Linking (ld)
(C) 2. Compiling (cc1)
(D) 3. Assembling (as)
Correct Answer: (A)
[EN] In Compilation Process in C: Preprocessing, Compiling, Assembling, Linking, '1. Preprocessing (cpp)' handles 'gcc -E : .c -> .i (expanded C text)' (Removes comments; expands #include and #define macros).
[HI] Compilation Process in C: Preprocessing, Compiling, Assembling, Linking में '1. Preprocessing (cpp)' का कार्य/विवरण 'gcc -E : .c -> .i (expanded C text)' (Removes comments; expands #include and #define macros) है।
Q18. Which option accurately describes '2. Compiling (cc1)' in Compilation Process in C: Preprocessing, Compiling, Assembling, Linking?
(Compilation Process in C: Preprocessing, Compiling, Assembling, Linking के संदर्भ में '2. Compiling (cc1)' की सही विशेषता कौन सी है?)
(A) gcc -c : .s -> .o / .obj (relocatable object)
(B) gcc .o -> a.out / app.exe (executable)
(C) gcc -S : .i -> .s (assembly mnemonics)
(D) gcc -E : .c -> .i (expanded C text)
Correct Answer: (C)
[EN] '2. Compiling (cc1)' provides 'gcc -S : .i -> .s (assembly mnemonics)' — key point: AST parsing & type check; catches missing ';' syntax errors.
[HI] '2. Compiling (cc1)' का मुख्य विवरण 'gcc -S : .i -> .s (assembly mnemonics)' है (AST parsing & type check; catches missing ';' syntax errors)।
Q19. In Compilation Process in C: Preprocessing, Compiling, Assembling, Linking, identify the correct parameter for the specification: "gcc -c : .s -> .o / .obj (relocatable object)".
(Compilation Process in C: Preprocessing, Compiling, Assembling, Linking में "gcc -c : .s -> .o / .obj (relocatable object)" विवरण किस विकल्प के लिए सही है?)
(A) 2. Compiling (cc1)
(B) 4. Linking (ld)
(C) 3. Assembling (as)
(D) 1. Preprocessing (cpp)
Correct Answer: (C)
[EN] '3. Assembling (as)' corresponds to 'gcc -c : .s -> .o / .obj (relocatable object)' (Generates machine opcodes & unresolved symbol table).
[HI] '3. Assembling (as)' का संबंध 'gcc -c : .s -> .o / .obj (relocatable object)' (Generates machine opcodes & unresolved symbol table) से है।
Q20. Considering Compilation Process in C: Preprocessing, Compiling, Assembling, Linking, what key behavior defines '4. Linking (ld)'?
(Compilation Process in C: Preprocessing, Compiling, Assembling, Linking में '4. Linking (ld)' की मुख्य भूमिका या मान क्या है?)
(A) gcc -S : .i -> .s (assembly mnemonics)
(B) gcc -E : .c -> .i (expanded C text)
(C) gcc .o -> a.out / app.exe (executable)
(D) gcc -c : .s -> .o / .obj (relocatable object)
Correct Answer: (C)
[EN] '4. Linking (ld)' represents 'gcc .o -> a.out / app.exe (executable)' (Binds CRT & libraries; catches undefined/multiple symbols).
[HI] '4. Linking (ld)' का अर्थ/मान 'gcc .o -> a.out / app.exe (executable)' है (Binds CRT & libraries; catches undefined/multiple symbols)।
Compilation Process in C: Preprocessing, Compiling, Assembling, Linking — Exam FAQs
Q1: What is the exact difference between a Compiler Error and a Linker Error?
Compiler Error और Linker Error के बीच सटीक अंतर क्या है?
[EN] A Compiler Error happens during translation of one file (.i -> .s) due to invalid C syntax or type mismatches (e.g., missing ';'), whereas a Linker Error occurs when combining .o files and libraries because a function/global is missing ('undefined reference') or duplicated ('multiple definition').
[HI] Compiler Error गलत सिंटैक्स या डेटा टाइप के कारण (.i -> .s के दौरान) आता है, जबकि Linker Error तब आता है जब एक से अधिक .o फाइलों को जोड़ते समय किसी फंक्शन की परिभाषा न मिले या दो जगह मिल जाए।
Q2: What are the .text, .data, and .bss sections seen inside an object/executable file?
ऑब्जेक्ट या एक्जीक्यूटेबल फाइल में दिखने वाले .text, .data और .bss सेगमेंट क्या होते हैं?
[EN] .text stores compiled executable CPU instructions (read-only), .data stores initialized global/static variables, .rodata holds read-only constants/string literals, and .bss holds uninitialized (zero-filled) global/static variables.
[HI] .text में निष्पादनीय मशीन कोड, .data में मान दिए गए ग्लोबल/स्टैटिक वेरिएबल्स, .rodata में रीड-ओनली स्थिरांक तथा .bss में बिना प्रारंभिक मान वाले (0 से भरे) ग्लोबल/स्टैटिक वेरिएबल्स रहते हैं।
Q3: How do you compile a multi-file C project (main.c + math_utils.c) cleanly in GCC?
GCC में मल्टी-फाइल C प्रोजेक्ट (main.c + math_utils.c) को सही ढंग से कैसे कंपाइल किया जाता है?
[EN] Either in one step 'gcc main.c math_utils.c -o app' or incrementally: 'gcc -c main.c', 'gcc -c math_utils.c', and then 'gcc main.o math_utils.o -o app'.
[HI] या तो एक साथ 'gcc main.c math_utils.c -o app' चलाएँ, या चरणबद्ध तरीके से पहले दोनों के लिए '-c' से .o फाइलें बनाएँ और अंत में दोनों .o फाइलों को लिंक करें।
Post a Comment
Post a Comment