Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gcc builds with -o but not -o3?

My Makefile looks like this:

CC=gcc
CFLAGS=-Wall -Wextra -std=c99 -pedantic
OBJECTS=main.o Scene.o Matrix.o Vector.o Triangle.o Color.o Raster.o

render: $(OBJECTS)
    $(CC) $(CFLAGS) -lm -o render -g $(OBJECTS)
    rm $(OBJECTS)

clean:
    rm -f render*

This builds my executable with no errors, but when I change -o to -o2 or -o3, I get the error:

gcc -Wall -Wextra -std=c99 -pedantic   -c -o main.o main.c
gcc -Wall -Wextra -std=c99 -pedantic   -c -o Scene.o Scene.c
gcc -Wall -Wextra -std=c99 -pedantic   -c -o Matrix.o Matrix.c
gcc -Wall -Wextra -std=c99 -pedantic   -c -o Vector.o Vector.c
gcc -Wall -Wextra -std=c99 -pedantic   -c -o Triangle.o Triangle.c
gcc -Wall -Wextra -std=c99 -pedantic   -c -o Color.o Color.c
gcc -Wall -Wextra -std=c99 -pedantic   -c -o Raster.o Raster.c
gcc -Wall -Wextra -std=c99 -pedantic -lm -o3 render -g main.o Scene.o Matrix.o Vector.o Triangle.o Color.o Raster.o
gcc.exe: error: render: No such file or directory
make: *** [render] Error 1

There could be some error in my code detected by the optimization flags, but as I don't get any error messages before this it's hard to know what's going wrong. I'm using MinGW/MSYS on Windows 7.

like image 591
dst2 Avatar asked Dec 10 '25 13:12

dst2


2 Answers

-o render means create the output file with the name render.

Now you are changing this -o to -o3 which is incorrect. Instead you need to keep -o render as it is and add a -O3 flag for optimization. Note the capital letter O.

like image 75
codaddict Avatar answered Dec 12 '25 04:12

codaddict


-o is the output file flag. You were thinking of -O (capital).

like image 36
Fred Foo Avatar answered Dec 12 '25 05:12

Fred Foo



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!