Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc compiler error when using certain switches

Tags:

c

gcc

I'm trying to compile a simple "Hello, World" program using gcc in C programming language. I use the following command on a source code file "test.c" (without the quotes).

I use the following command:

gcc test.c -O -Wall -Werror test

I expect this to compile my program and create and executable called test that I can run the program with from the command line. However when I compile using the above line I get the following error:

gcc: test: No such file or directory

Any reason as to why this may be?

Thanks!

like image 306
Gasper Gulotta Avatar asked Jul 26 '26 17:07

Gasper Gulotta


2 Answers

gcc is treating test as an input file name. Assuming you want to use test as the output file name, you need to use the -o option.

gcc test.c -O -Wall -Werror -o test
                            ^^
like image 109
Drew McGowen Avatar answered Jul 29 '26 06:07

Drew McGowen


You are giving the wrong commands to gcc:

do this :

gcc -Werror -Wall -O -o test test.c 

-o is for output

like image 43
sukhvir Avatar answered Jul 29 '26 07:07

sukhvir



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!