I've currently run in such a problem, in fact caused by the package maintainer(s), who simply did not consider that a certain preprocessor definition was not available until version X of a certain toolkit package required in the dependencies (which is currently in testing stage). It was fixable by simply adding an additional #define
to a header file in the base system, making the project compile fine again.
However, what if I had no root access to the system? Could I also add a #define new_macro "i am from the future"
at compile time, e. g. to configure
?
When reading myself through the matter, I thought that it might maybe work with the DEFS
environment variable, but apparently this is not meant to be used for C preprocessor directives.
So can this be accomplished at all?
Asked
Active
Viewed 79 times
1

syntaxerror
- 661
- 2
- 6
- 24
-
1`gcc -DSOME_MACRO="some_value"`? – twalberg Jul 30 '14 at 19:42
-
Yes this would basically work, but this will require me to directly edit the `gcc` parameters, which I actually wanted to avoid. This is none the less awkward as editing the header file of the depending package directly. – syntaxerror Jul 30 '14 at 20:23
-
1You should be able to do something like `./configure CC='gcc -Dnew_macro="i am from the future"'` (syntax?) to replace the actual `gcc` command in the file with the one+parameter? – Alex Celeste Jul 31 '14 at 00:57
-
Thanks, but unfortunately a huge problem is the strings in quotes. Even escaping them by a backslash did not work. Not until I really hacked in the `#define` into the file in the `/usr` tree the project would finally compile. Otherwise it would always split up a constant `first-second` into `first` and `second`, breaking every function call. – syntaxerror Aug 08 '14 at 01:33
1 Answers
0
Thanks, but unfortunately a huge problem is the strings in quotes
Create a file, for example at ~/somedir/mycompiler
with content:
#!/bin/sh
gcc -Dnew_macro="i am from the future" "$@"
add executable permissions chmod +x ~/somedir/mycompiler
and then pass that as parameter to configure
:
./configure CC="$HOME"/somedir/mycompiler ...
Configure script in turn will use that script to compile everything, passing -D
everywhere, and quotes will be properly parsed by sh
.