Access to the GCC Compiler from an Internal C / C ++ Program

Is it possible to access gcc compilers, was the c / C ++ program compiled from within the program?

In my application, as part of the registration information, I would like to write with which switches the program was compiled, for example, using a compiler, including optimization and a preprocessor variable.

+3
source share
5 answers

There is no standard way.

Typically, the build system generates such things in the version line that is built into the application (but not one of them is automatic).

+6
source

Martin : Vim - grep all_cflags all_lflags.

+4

http://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html

 __OPTIMIZE__
 __OPTIMIZE_SIZE__
 __NO_INLINE__

__OPTIMIZE__ . __OPTIMIZE_SIZE__ , , . __NO_INLINE__ , ( , -fno-inline).

, /make script, .h .

+4

gcc- script, . , :

#!/bin/sh

echo "#define GCC_OPTIONS \"$*\"" > gcc_options.h
exec gcc $@

script gcc_wrap -O0 main.c , main.c.

#define GCC_OPTIONS "-O0 main.c"
+2

In one of my projects, each assembly fell into its own directory, and usually the entire assembly had a specific name, such as "parallel-debug" or "singlethread-O2". Usually the log file in this directory gave us all the information implicitly from its location.

In any case, you can make $ (CC) or $ (FLAGS) or any other variables appear in the text file, and then your program will read this file at startup. It’s not a metamagy and Scott Myers may not interview you for effective C ++ VII, but this problem does not seem to deserve such a big headache.

0
source

Source: https://habr.com/ru/post/1784352/


All Articles