Errors not showing when compiling with gcc and clang

When i compile a c file that has an error for example missing semicolon with either gcc or clang there isn’t an error message.
The only way to get an error message is to open a new terminal tab.

Demonstrate this with some copy and pasted output from the terminal, so we can see what you’re doing and replicate it.

Both clang and gcc perform as expected for me:

┌─🎩 lurcher ~
├─
└─➜ clang file.c                                                                                                                                         15:38 Fri 20-Mar
file.c:1:1: warning: return type of 'main' is not 'int' [-Wmain-return-type]
    1 | void main()
      | ^
file.c:1:1: note: change return type to 'int'
    1 | void main()
      | ^~~~
      | int
file.c:3:3: error: call to undeclared library function 'printf' with type 'int (const char *, ...)'; ISO C99 and later do not support implicit
      function declarations [-Wimplicit-function-declaration]
    3 |   printf("wibble")
      |   ^
file.c:3:3: note: include the header <stdio.h> or explicitly provide a declaration for 'printf'
file.c:3:19: error: expected ';' after expression
    3 |   printf("wibble")
      |                   ^
      |                   ;
1 warning and 2 errors generated.

┌─🎩 lurcher ~
├─
└─➜ gcc file.c                                                                                                                                           15:38 Fri 20-Mar
file.c: In function ‘main’:
file.c:3:3: error: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
    3 |   printf("wibble")
      |   ^~~~~~
file.c:1:1: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
  +++ |+#include <stdio.h>
    1 | void main()
file.c:3:3: warning: incompatible implicit declaration of built-in function ‘printf’ [-Wbuiltin-declaration-mismatch]
    3 |   printf("wibble")
      |   ^~~~~~
file.c:3:3: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
file.c:3:19: error: expected ‘;’ before ‘}’ token
    3 |   printf("wibble")
      |                   ^
      |                   ;
    4 | }
      | ~

Please share a small C program that shows the problem.
Then we can try and reproduce what you are seeing.

However I find it odd that you say the fix is to use a new terminal tab.
Maybe you changed something important in the terminal that shows no errors.
For example have you rediected stdout and or stderr to a file?

#include <stdio.h>
int main(){
printf(“Hello world”)
return 0;
}

if i compile this c program it won’t show any error unless i make a new tab and recompile it then it will tell me that there is a missing semicolon.Also if i clear the new terminal tab before fixing the error and i tried to recompile the program it won’t show an error message

As the issue is not with either of the compilers, what terminal are you using and what config do you have associated with that terminal?

What have you customised in your profile/bashrc/whatever config file is appropriate for your shell?

I use ghostty but this also happens in konsole.

This is my ~/.zshrc, the big words are comments

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH

# Path to your Oh My Zsh installation.
export ZSH="$HOME/.oh-my-zsh"

# Set name of the theme to load --- if set to "random", it will
# load a random theme each time Oh My Zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
#ZSH_THEME="robbyrussell"
ZSH_THEME="agnoster"

# Set list of themes to pick from when loading at random
# Setting this variable when ZSH_THEME=random will cause zsh to load
# a theme from this variable instead of looking in $ZSH/themes/
# If set to an empty array, this variable will have no effect.
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )

# Uncomment the following line to use case-sensitive completion.
# CASE_SENSITIVE="true"

# Uncomment the following line to use hyphen-insensitive completion.
# Case-sensitive completion must be off. _ and - will be interchangeable.
# HYPHEN_INSENSITIVE="true"

# Uncomment one of the following lines to change the auto-update behavior
# zstyle ':omz:update' mode disabled  # disable automatic updates
# zstyle ':omz:update' mode auto      # update automatically without asking
# zstyle ':omz:update' mode reminder  # just remind me to update when it's time

# Uncomment the following line to change how often to auto-update (in days).
# zstyle ':omz:update' frequency 13

# Uncomment the following line if pasting URLs and other text is messed up.
# DISABLE_MAGIC_FUNCTIONS="true"

# Uncomment the following line to disable colors in ls.
# DISABLE_LS_COLORS="true"

# Uncomment the following line to disable auto-setting terminal title.
# DISABLE_AUTO_TITLE="true"

# Uncomment the following line to enable command auto-correction.
# ENABLE_CORRECTION="true"

# Uncomment the following line to display red dots whilst waiting for completion.
# You can also set it to another string to have that shown instead of the default red dots.
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
# COMPLETION_WAITING_DOTS="true"

# Uncomment the following line if you want to disable marking untracked files
# under VCS as dirty. This makes repository status check for large repositories
# much, much faster.
# DISABLE_UNTRACKED_FILES_DIRTY="true"

# Uncomment the following line if you want to change the command execution time
# stamp shown in the history command output.
# You can set one of the optional three formats:
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
# or set a custom format using the strftime function format specifications,
# see 'man strftime' for details.
# HIST_STAMPS="mm/dd/yyyy"

# Would you like to use another custom folder than $ZSH/custom?
# ZSH_CUSTOM=/path/to/new-custom-folder

# Which plugins would you like to load?
# Standard plugins can be found in $ZSH/plugins/
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
# Example format: plugins=(rails git textmate ruby lighthouse)
# Add wisely, as too many plugins slow down shell startup.
#plugins=(git)
plugins=(git zsh-autosuggestions zsh-syntax-highlighting fast-syntax-highlighting zsh-autocomplete)
source $ZSH/oh-my-zsh.sh

# User configuration

# export MANPATH="/usr/local/man:$MANPATH"

# You may need to manually set your language environment
# export LANG=en_US.UTF-8

# Preferred editor for local and remote sessions
# if [[ -n $SSH_CONNECTION ]]; then
#   export EDITOR='vim'
# else
#   export EDITOR='nvim'
# fi

# Compilation flags
# export ARCHFLAGS="-arch $(uname -m)"

# Set personal aliases, overriding those provided by Oh My Zsh libs,
# plugins, and themes. Aliases can be placed here, though Oh My Zsh
# users are encouraged to define aliases within a top-level file in
# the $ZSH_CUSTOM folder, with .zsh extension. Examples:
# - $ZSH_CUSTOM/aliases.zsh
# - $ZSH_CUSTOM/macos.zsh
# For a full list of active aliases, run `alias`.
#
# Example aliases
# alias zshconfig="mate ~/.zshrc"
# alias ohmyzsh="mate ~/.oh-my-zsh"
eval "$(starship init zsh)"
fastfetch
1 Like

Edit and post that as pre-formatted text please - its deeply unpleasant to read and compare with something I’d expect to see.

Let’s also see your aliases and the exact command you’re using to compile your code and the output it generates.

You could also try running bash -x inside your terminal and posting what you get when you run that same gcc or clang compile command.

FYI I fixed your markup to use the pre-formatted text.
You enclose the lines like this

```
line 1
line 2
```

i use gcc test.c -o test.exe to compile it

In the terminal try this:

echo "is stdout working"
echo "is stderr working" 1>&2

What do you see?

i see:

is stdout working
is stderr working

and when you run gcc with the bad C file no output?

If gcc bad.c does not work try this /usr/bin/gcc bad.c
Maybe you have an alias or gcc on your PATH somehow?

if it is a new file it won’t create a .exe file
if it is an old file that already has a .exe it will show that last successful compilation

.exe is a Windows OS thing, not sure what you are talking about.

Are you running gcc via a make file? IF so I don;t think you said that is what you are doing.

On Fedora gcc always produces a file, a.out if you do not set the output name.
It never skips compiling

This also dosen’t work

You need to share the exact command you are running and any output you see with us.

yes i mean .out