التصريح عن الملفات التنفيذية والمكتبات
أضيفوا المخرجات إلى مخطط البناء
التصريح عن الملفات التنفيذية والمكتبات درس مجاني في Zig Academy على CoddyKit. هذا هو الدرس 2 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Zig Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Zig Academy 4 دروس في المجموع.
بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.
Artifacts to Build
The things you compile are called artifacts: an executable you run, or a library other code links against. You declare them in build.zig. 📦
Add an Executable
Create a runnable program with addExecutable. You give it a name and the root source file that holds main.
const exe = b.addExecutable(.{
.name = "app",
});Point to the Root Module
The artifact needs a root_module built from your main file, plus the target and optimize values you chose earlier.
.root_module = b.createModule(.{
.root_source_file = b.path("src/main.zig"),
}),Carry Target and Optimize
That module also takes the target and optimize fields, so the executable honors whatever the command line requested.
.target = target,
.optimize = optimize,Install the Output
Creating an exe is not enough; tell Zig to place it in zig-out with installArtifact so the default build emits it.
b.installArtifact(exe);Where Outputs Land
Installed binaries appear under zig-out/bin by convention. Run zig build and look there for your freshly compiled program.
zig-out/bin/appAdd a Library
For reusable code, use addLibrary instead. It produces a library artifact others can import and link against.
const lib = b.addLibrary(.{
.name = "mathz",
});Static or Dynamic
A library can be static (baked into the caller) or dynamic (a shared file). You set linkage when you declare the library.
.linkage = .static,Link Library into Exe
Connect them so the exe can call the library's code: use linkLibrary to add the dependency edge.
exe.linkLibrary(lib);Need libc?
If your code calls C standard functions, request libc on the artifact with linkLibC so the right system library is linked.
exe.linkLibC();A Graph of Artifacts
Each artifact is a node; linking adds edges. Together they form the build graph Zig walks when you run the build. ✅
Quick Check
Recall which call actually emits a built binary into zig-out.
Recap
You declared artifacts with addExecutable and addLibrary, set their root module and target, then used installArtifact and linkLibrary to wire them. 🎯
الأسئلة الشائعة
هل درس «التصريح عن الملفات التنفيذية والمكتبات» مجاني؟
نعم — نص درس «التصريح عن الملفات التنفيذية والمكتبات» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Zig Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Zig Academy 4 دروس في المجموع.
ماذا ستتعلم في «التصريح عن الملفات التنفيذية والمكتبات»؟
أضيفوا المخرجات إلى مخطط البناء تتمرن على Zig Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.
هل أحتاج إلى خبرة سابقة لأبدأ Zig Academy؟
لا تُشترط خبرة سابقة. Zig Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 2 من أصل 4.
كم من الوقت يستغرق درس «التصريح عن الملفات التنفيذية والمكتبات»؟
معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.
هل يمكنني كتابة وتشغيل أكواد في درس Zig Academy هذا؟
نعم. كل درس في Zig Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.
جميع الدروس في هذه الدورة
- بنية ملف build.zig
- التصريح عن الملفات التنفيذية والمكتبات
- خطوات البناء وzig build run
- خيارات البناء والرايات