简体   繁体   中英

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.

-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 .

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM