Skip to content

emka.web.id

writing knowledge, recording civilization

Menu
  • Home
  • Tutorial
  • Search
Menu

Cara Coding C/C++ di Ubuntu 24.04 dengan GCC

Posted on June 6, 2024

Merasa udah jago ngoding? Pengen ngebangun program sendiri dari awal? Keren! Tapi, ada satu langkah penting yang harus kamu lewati dulu: kompilasi. Nah, biar proses kompilasi lancar, kamu butuh senjata ampuh bernama GCC.

Apa itu GCC?

GCC (GNU Compiler Collection) adalah compiler handal yang bisa mengubah kode program yang kamu tulis menjadi bahasa yang bisa dipahami komputer. Tanpa compiler, program C/C++ keren kamu cuma tulisan indah yang nggak bisa dieksekusi.

Yuk, langsung kita praktikkan di Ubuntu 24.04!

Persiapan Sebelum Ngoding

  • Editor Teks: Sebenarnya bebas kamu mau pakai editor teks apa aja. Pilihan populer ada nano, Vim, atau Visual Studio Code. Untuk pemula, nano cukup mudah digunakan.
  • Terminal: Ini jendela tempat kamu ngetik perintah di Linux. Biasanya bisa diakses dengan menekan Ctrl + Alt + T di keyboard.

Menulis Kode Program Pertama

  1. Buka Editor Teks: Buka terminal, lalu ketik perintah nano myprogram.c (untuk program C) atau nano myprogram.cpp (untuk program C++). Perintah nano digunakan untuk membuka editor nano, sedangkan myprogram.c atau myprogram.cpp adalah nama file program kamu. Tekan enter untuk membuka file tersebut.
  2. Masukkan Kode: Sekarang saatnya menulis kode program! Salin dan tempelkan kode berikut ke dalam file:
#include <stdio.h>

int main() {
    printf("Hello, World!\n");
    return 0;
}

Penjelasan Kode:

  • #include <stdio.h>: Baris ini menyertakan library stdio.h yang berisi fungsi-fungsi untuk input dan output data, seperti printf.
  • int main(): Fungsi main adalah fungsi utama program yang akan dieksekusi pertama kali.
  • printf("Hello, World!\n"): Baris ini menggunakan fungsi printf untuk mencetak tulisan “Hello, World!” ke terminal diikuti dengan karakter newline (\n).
  • return 0;: Baris ini menandakan program selesai dijalankan dengan sukses (nilai 0).
  1. Simpan File: Setelah selesai menulis kode, tekan Ctrl + O untuk menyimpan file. Ketik nama file (myprogram.c atau myprogram.cpp) dan tekan enter. Kemudian, tekan Ctrl + X untuk keluar dari nano.

Kompilasi: Mengubah Kode Menjadi Bahasa Mesin

Sekarang saatnya mengubah kode program yang kamu tulis menjadi bahasa yang bisa dimengerti komputer. Ini dia peran GCC!

  1. Kompilasi Kode: Kembali ke terminal dan ketik perintah berikut sesuai dengan bahasa program kamu:
  • C program: gcc myprogram.c -o myprogram
  • C++ program: g++ myprogram.cpp -o myprogram Penjelasan Perintah:
  • gcc atau g++: Ini adalah perintah untuk memanggil compiler GCC (untuk C) atau G++ (untuk C++).
  • myprogram.c atau myprogram.cpp: Ini adalah nama file program kamu yang akan dikompilasi.
  • -o myprogram: Opsi -o digunakan untuk menentukan nama file output program yang dihasilkan setelah kompilasi. Di sini, kita beri nama myprogram. Tekan enter untuk menjalankan perintah kompilasi. Jika proses kompilasi berhasil, tidak akan ada pesan yang ditampilkan di terminal. Namun, jika terjadi kesalahan, pesan error akan ditampilkan dan kamu perlu memperbaiki kode program kamu sesuai dengan pesan tersebut.

Menjalankan Program yang Dikompilasi

Setelah proses kompilasi selesai, program kamu sudah siap dijalankan! Ketik perintah berikut di terminal:

./myprogram

Tekan enter dan lihat keajaibannya! Terminal akan menampilkan tulisan “Hello, World!”. Selamat! Kamu baru saja berhasil menulis, mengkompilasi, dan menjalankan program C/C++ pertama kamu di Ubuntu 24.04.

Tips dan Trik Menjadi Master Ngoding

  • Eksplorasi!: Kode yang kamu buat di atas hanyalah permulaan. Coba ubah isi kode untuk menampilkan pesan yang berbeda atau lakukan operasi matematika sederhana.
  • Pelajari Dokumentasi: Dokumentasi resmi GCC dan library

Terbaru

  • The End of ClickOps: Why Manual AWS Configuration is Your Biggest Security Debt
  • API Keys vs. Service Accounts vs. OAuth: How do you pick the right credential on Google Cloud?
  • Why Your Private Subnet is Offline: The DevOps Interview Breakdown
  • The Laravel-ification of Everything: Why Go and Rust are Racing to Steal PHP’s Crown
  • Why Redis is actually fast
  • The Fake 2FA Scandals and Fake AI Apps on Microsoft Store
  • Stop Overengineering Your Infrastructure: Docker Compose vs Kubernetes Resources
  • Traefik 3.8 New Feature: Yaegi v2 and the Gateway API Finally Make Custom Plugins Worth the Effort
  • Raspberry Pi OS: Why the November Update is a Win for Minimalism
  • React Can useState Hook Explained in 60 Seconds
  • How Do You Build an MMO Solo?
  • NixOS 26.11 “Zokor” Might Be the Most Practical Release for Desktop Power Users Yet
  • Why Your AWS Bill Can Just Tripled Overnight?
  • Why Indonesia’s Battle with Google is a Dangerous Game of Chicken
  • SYS010 Malware Explained: How Malvertising on Meta Bypasses MFA and Hijacks Your Digital Identity
  • Linux Mint 27 Adrien: Why This Version Jump is Make Sense?
  • NFS2ROOT: A 12-Year Reminder That Your Linux Kernel Is Never Truly Safe
  • The Death of Browsing and the Rise of the “Answer Engine Economy”
  • What’s new in Proxmox VE 9.3?
  • Why Your Morning Routine Needs an API: The Art of iOS Automation
  • Proof of Work is the New Certification: 5 AWS Projects to Build Before 2027
  • Omarchy is Our first agentic operating system
  • The Death of Popper.js: Why CSS Anchor Positioning is the New Standard for Connected UI
  • Why Your 2027 Cloud Career Depends on Moving Beyond Basic AWS Services
  • Why Discord is Ditching Electron for Rust: Is GPUi Actually the Future?
  • The End of the KDE Era: Why KaOS 2026.11 Is a Bold, Dangerous Gamble
  • The $2 Billion Code: Why GTA 6 is a Technical Miracle and a Hardware Nightmare
  • LibreDB Studio Explained
  • PHP 8.6 Is Officially Out: What’s New, What Breaks, and How We’re Upgrading
  • Rewriting Legacy Apps: 4 Data Migration Strategies That Actually Work
  • Canonical: Ubuntu coming soon to Snapdragon X2 Series platforms
  • Finally, wolfSSL adds post-quantum algorithms!
  • How to Run Gemma Embedding Models Using Docker
  • Deploy Nginx Rootful Container with Podman
  • How to Sandboxing Browser on Linux Desktop with Flatpak
  • Why HALO Agent OS Marks a Shift Toward Agentic Content Ecosystems?
  • The Qwen4-35B-A3B: Is This the “Impossible” Model for Local AI?
  • Why Running LLMs Locally in Python is No Longer Optional for Serious Developers
  • Digital Ghetto: People are hacking their own houses with Claude
  • How to Let ChatGPT Control Your Computer From Your Phone (Step-by-Step)

©2026 emka.web.id | Design: Newspaperly WordPress Theme