I'm attempting to write a shell script that will run several tests of my C++ program, redefining a macro each time it runs. I'm trying to use the -D name preprocessor option (see https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html), but I'm consistently getting the warning that the macro is being redefined, and then the program executes without redefining it.
My script is as follows:
#!/bin/bash
#NUMS is number of subdivisions:
for subdiv in 10 100 500 1000
do
echo NUMS = $subdiv
g++ -D NUMS=$subdiv project01.cpp -o project01 -lm -fopenmp
./project01 >> bezier_results.txt
done
In my C++ file, project01.cpp, I state:
#define NUMS 1
I've tried leaving out the '1', but that produces errors as well. It's clear that the script isn't actually redefining the macro. Any thoughts? Thanks!
#ifndef NUMS/#endifpair. As to It's clear that the script isn't actually redefining the macro - you're right. The redefinition happened in your#define NUMS 1source. The command line was seen first.