When invoking GCC, one provides an option in the form of "-mcpu=cortex-m4" to specify the CPU type.
It there a way at run time to get the -m CPU string that GCC was invoked with??
Thanks
When invoking GCC, one provides an option in the form of "-mcpu=cortex-m4" to specify the CPU type.
It there a way at run time to get the -m CPU string that GCC was invoked with??
Thanks
You can achieve this with some clever compiling. If, for example, you use a Makefile you can put your flags into a variable and then use that variable to set a macro using the GCC -D flag a bit like this:
COMPILER_FLAGS=-std=c++11 -thread -O3
program: program.cpp
$(CXX) -DEXTERNAL_COMPILER_FLAGS="\"$(COMPILER_FLAGS)\"" $(COMPILER_FLAGS) -o $@ $<
Then in the C++ source file you can have:
#include <iostream>
#ifndef EXTERNAL_COMPILER_FLAGS
#define COMPILER_FLAGS "not set"
#else
#define COMPILER_FLAGS EXTERNAL_COMPILER_FLAGS
#endif
int main()
{
std::cout << COMPILER_FLAGS << '\n';
}
If you don't use a Makefile you should be able to find an equivalent method in whatever build system you use.
GCC has the -frecord-gcc-switches option for that. It will cause your binary to record/contain the compiler options used, in a special section that can then be extracted later.
Without that option, there's no way to know.
Look up details at https://gcc.gnu.org/onlinedocs/gcc/Code-Gen-Options.html