I have a problem ; that i can't compile and Run my C files in Ubuntu , so how can i do this??

Dani AI

Generated

A short, practical follow-up to and : verify the compiler, a minimal compile/run example, and the most common fixes that keep this thread from becoming a dead end.

To confirm a C toolchain is present, check the compiler version:

gcc --version

A minimal source file (save as plain-text with a .c extension) and the typical compile/run sequence:

/* hello.c */
#include <stdio.h>

int main(void) {
    puts("Hello, world");
    return 0;
}

# compile and run
gcc -Wall -Wextra -std=c11 -O2 -o hello hello.c
./hello

For more than one source file use:

gcc -o myprog main.c other.c

Troubleshooting notes (common causes and remedies):

  • "gcc: command not found" — the system lacks a C toolchain; install the base development tools using the distribution package manager (Ubuntu uses apt) with elevated privileges (the earlier posts point this out).
  • Missing headers like stdio.h — the C runtime headers/dev packages are not installed; installing the development meta-package will supply them.
  • Permission denied when running hello — run the executable as ./hello (current directory) or set an execute bit if needed.
  • Lots of warnings/errors — compile with -Wall -Wextra to reveal problems; fix the source rather than ignoring warnings.
  • Linking errors (undefined references) — ensure all object/source files are passed to the linker and add libraries (for math use -lm) if required.

These steps expand on 's and 's suggestions and cover the next things that commonly block compilation on Ubuntu.

Recommended Answers

All 3 Replies

I have a problem ; that i can't compile and Run my C files in Ubuntu , so how can i do this??

Do you have a c compiler installed?

if not do :

sudo apt-get install build-essential
Member Avatar for Member #2466

Ubuntu doesn't contain the GCC compiler by default...they seem to think it is too dangerous to include.

Using the command referenced above will take care of you.

Hmm. Ok thanks i will try that. thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.