1

Trying to compile following code in terminal i got

root@debian:/home/mz2/Documentos# LANG=C ./soma.c 
./soma.c: line 2: syntax error near unexpected token `('
./soma.c: line 2: `int soma (int a, int b);'

The file soma.c is

#include < stdio.h >
int soma (int a, int b);
int main (int argc, char **argv) {
     int x, y, z;
     x = 10;
     y = 12;
     z = soma(x, y);
     fprintf(stdout, "A soma de %d com %d é %d\n", x, y, z);
     return 0;
  }
  int soma (int a, int b) {
  return (a + b);
  }

When I run

  root@debian:/home/mz2/Documentos# LANG=C gcc -o soma soma.c
  soma.c:1:21: fatal error:  stdio.h : No such file or directory
  compilation terminated.

And...

  root@debian:/home/mz2/Documentos# LANG=C gcc -Wall -Wextra -pedantic -o    soma soma.c
  soma.c:1:21: fatal error:  stdio.h : No such file or directory
  compilation terminated.

How can I fix this and run it?

closed as off-topic by Braiam, jimmij, Faheem Mitha, John WH Smith, jasonwryan Jan 19 '15 at 0:38

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Braiam, Faheem Mitha, John WH Smith, jasonwryan
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Your title didn't match your question: you didn't even try to run gcc. – Gilles Jan 18 '15 at 21:46
6

You have to compile it; as in:

gcc -o soma soma.c

Then run by:

./soma

As of now you are running is as a script with what ever shell you are using.

A better compile line would be:

gcc -Wall -Wextra -pedantic -o soma soma.c

That line will give you a lot of help and hints. And always remember to compile often so you do not have to fix walls of errors at the same time.

To enhance the user experience you can also try out colorgcc (if available). A wrapper for gcc that outputs colorized warnings, errors etc.

Also available here by http://schlueters.de/colorgcc.html


You also have an error in your code as you have spaces around < and > in include:

#include < stdio.h >

Should be:

#include <stdio.h>
  • Sorry, but this command didn't fix it.... Please see above – Vitor Mazuco Jan 18 '15 at 21:59
  • @VitorMazuco: See update. – user367890 Jan 18 '15 at 22:01
  • @VitorMazuco: Also note that you should use a proper editor. Most have some way to add extra help for you in the editor (giving you errors and warnings in editor - so you do not have to even try to compile.) Example: Sytastic for vim: vim.org/scripts/script.php?script_id=2736 - If you use another editor try to find out if it has plugins or similar to help out. – user367890 Jan 18 '15 at 22:29
  • @VitorMazuco: Also not that there is no need for LANG=C on your compile line ... I also suspect you have done chmod +x soma.c as you are able to execute it. That is nor needed (or desirable). – user367890 Jan 18 '15 at 22:38
  • Also make sure lib6-dev is installed: sudo apt-get install libc6-dev – James Draper Jun 7 '18 at 19:14

Not the answer you're looking for? Browse other questions tagged or ask your own question.