CC Lab
หลักสูตรการเขียนโปรแกรมภาษา C
ความคืบหน้าเก็บไว้ในเบราว์เซอร์นี้โหมดผู้เรียน
บทเรียน / หลายไฟล์และเฮดเดอร์ / 06

เชื่อมไฟล์ object ด้วย linker

เข้าใจเชื่อมไฟล์ object ด้วย linkerและนำไปใช้กับโปรแกรม C ได้

แนวคิดและการทดลองประมาณ 12 นาที
บทที่ 6 จาก 7
แนวคิดหลัก

ลองสังเกตตัวอย่าง แล้วค่อยเปลี่ยนค่าเพื่อดูว่าแนวคิดเรื่องเชื่อมไฟล์ object ด้วย linkerส่งผลต่อโปรแกรมอย่างไร

ลงมือสำรวจ

เปลี่ยนค่าและสังเกตผล
Project file tree
root/ grade-project├ main.c├ grade.c└ grade.h
main.c → #include "grade.h" · grade.c → implement grade_from_score · linker รวม object files

อ่านโค้ดตัวอย่าง

// grade.h
#ifndef GRADE_H
#define GRADE_H
int grade_from_score(int score);
#endif

// main.c includes grade.h and calls the function

ทำนายผลก่อนทดลอง

Prediction

ไฟล์ header ควรถูกส่งให้ GCC เป็น translation unit แยกหรือไม่?

main.c · แยก prototype ไป grade.h และ implementation ไป grade.c
กำลังโหลดตัวแก้ไขโค้ด…

บันทึกโค้ดไว้ใน localStorage ของเบราว์เซอร์นี้ หากเปิดใช้งานการรัน โค้ดและ stdin จะถูกส่งไปยัง Wandbox

จบบทเรียน

Draft lesson. Progress is not recorded.
กลับไปยังโมดูลบทถัดไป