Online GDB Compiler

Compile and run C and C++ code in your browser.

Run your code to see the output.

What Is an Online GDB Compiler?

GDB, the GNU Debugger, is the standard debugger for C and C++ programs on Linux. People often search for an online GDB compiler when they want to test C or C++ code without installing a toolchain.

This tool compiles and runs your code with GCC in a sandbox, and shows the output, compiler errors and any crash signal. It doesn't include an interactive GDB session, so you can't set breakpoints or step through code here. For that, install GDB on your own computer and use the commands listed in this article.

How to Use It

  1. The editor opens with a C sample. Use the language menu to switch to C++ or another language.
  2. Write or paste your program.
  3. If your program reads input, add it to the Standard Input panel before you run it. The program can't stop and wait for you to type.
  4. Select Run code, or press Ctrl+Enter (Cmd+Enter on a Mac).

Reading the Result

ResultWhat it meansWhat to do
Compile errorGCC couldn't build the programStart with the first error, since later ones often follow from it
Runtime Error (SIGSEGV)The program accessed memory it shouldn't, often through a null or invalid pointer or by going past the end of an arrayCheck pointers and array bounds near the last output you see
Runtime Error (SIGFPE)An arithmetic error, usually an integer divided by zeroCheck divisors before dividing
Runtime Error (SIGABRT)The program stopped itself, often through a failed assert, an uncaught C++ exception or corrupted memoryCheck assertions, exceptions and free or delete calls
Runtime Error (NZEC)main returned a value other than zeroCheck your return and exit values
Time limit exceededThe program ran past the time limit, usually in an endless loopCheck loop conditions, including loops that keep reading after the input runs out

Debugging Without GDB

Without breakpoints, print statements are the quickest way to find where a program goes wrong. Output is often held in a buffer and can be lost in a crash, so write it out straight away:

c
#include <stdio.h>

int main(void) {
    /* Write all output immediately, so a crash can't discard it */
    setvbuf(stdout, NULL, _IONBF, 0);

    printf("Before the suspect line\n");
    /* ... */
    printf("After the suspect line\n");
    return 0;
}

The last message you see shows that the problem comes after that line. Move the messages closer together until you find it.

Debugging With GDB on Your Computer

To use GDB itself, compile with debug information and without optimization, then start the program in GDB:

gcc -g -O0 main.c -o main
gdb ./main

For C++, use g++ in place of gcc. These commands cover most debugging sessions:

CommandWhat it does
break main or break main.c:12Stop at a function or line
run or run < input.txtStart the program, with input from a file if you need it
nextRun the next line without entering function calls
stepRun the next line and enter any function it calls
continueRun until the next breakpoint
print totalShow the value of a variable or expression
watch totalStop whenever a variable changes
backtraceShow the chain of function calls, which is the first thing to check after a crash
info localsShow the local variables in the current function
quitExit GDB

To find memory errors, also try compiling with -fsanitize=address. The program then reports invalid memory access with the location of the problem.

Limits

LimitValue
C and C++ compilerGCC 9.2.0
Source code size100,000 characters
Standard input size10,000 characters
CPU time per run5 seconds
Wall-clock time per run10 seconds
Network accessDisabled

Programs run from a single file, so you can't add your own headers or libraries.

For the full list of languages, see the Online Compiler. It uses the same engine and opens on Python.

More Developers tools
500 free credits a month, no card

Building your own app? Try the Geekflare API.

One API key for scraping, search, screenshots, DNS, PDF, and more.

bash
curl -X POST https://api.geekflare.com/webscraping \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com"}'