I've just started learning Linux and I'm having some trouble disabling GCC's optimization for one of my C++ projects.
The project is built with makefiles like so...
make -j 10 && make install
I've read on various sites that the command to disable optimization is something along the lines of...
gcc -O0 <your code files>
Could someone please help me apply this to makefiles instead of individual code? I've been searching for hours and have come up empty handed.
In some standard makefile settings you could
make -j10 -e CPPFLAGS=-O0
But the makefile might use other substitution variables or override the environment. You need to show us the Makefile in order to propose edits
The simplest (useful) makefile that allows debug/release mode is:
#
# Define the source and object files for the executable
SRC = $(wildcard *.cpp)
OBJ = $(patsubst %.cpp,%.o, $(SRC))
#
# set up extra flags for explicitly setting mode
debug: CXXFLAGS += -g
release: CXXFLAGS += -O3
#
# Link all the objects into an executable.
all: $(OBJ)
$(CXX) -o example $(LDFLAGS) $(OBJ) $(LOADLIBES) $(LDLIBS)
#
# Though both modes just do a normal build.
debug: all
release: all
clean:
rm $(OBJ)
Usage Default build (No specified optimizations)
> make
g++ -c -o p1.o p1.cpp
g++ -c -o p2.o p2.cpp
g++ -o example p1.o p2.o
Usage: Release build (uses -O3)
> make clean release
rm p1.o p2.o
g++ -O3 -c -o p1.o p1.cpp
g++ -O3 -c -o p2.o p2.cpp
g++ -o example p1.o p2.o
Usage: Debug build (uses -g)
> make clean debug
rm p1.o p2.o
g++ -g -c -o p1.o p1.cpp
g++ -g -c -o p2.o p2.cpp
g++ -o example p1.o p2.o
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With