Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eclipse define build variable in pre-build

I created simple shell script file in /tmp/test.sh

#!/bin/sh
echo 'aaaa'

In Eclipse->C/C++ Build->Setting->Build Step -> Pre-build steps->Command , I added TEST =/tmp/test.sh

Than in C/C++ Build->Setting->Tool Settings->Cross GCC Compiler ->Command line pattern , I tried to used this variable like -D ${TEST} so it pass -D aaaa (the output of shell script)

But in build console I didn't see that -D aaaa have been passed to gcc , In fact I didn't see -D at all

why is that? I want to set variable in pre-build that will be the output of shell script and use it with gcc command line pattern

How can I do that ?

like image 907
MicrosoctCprog Avatar asked Nov 07 '22 04:11

MicrosoctCprog


1 Answers

Apparently the CDT managed build does not allow running external commands for assigning environment variables, build variables or command line flags, thus executing the script at that stage doesn't work.

Not a direct answer to the question on how to do that with the gcc command line pattern, but if you really only want to pass defines to the preprocessor with results you got from the script, you may use the script instead to update or create a header file that is included somewhere, e.g.:

#!/bin/sh
echo "#ifndef __MYVARHEADER__" > ../include/myvarheader.h
echo "#define __MYVARHEADER__" >> ../include/myvarheader.h
echo "#define aaaa" >> ../include/myvarheader.h
echo "#endif" >> ../include/myvarheader.h

In Eclipse->C/C++ Build->Setting->Build Step -> Pre-build steps->Command, just execute /tmp/test.sh

like image 99
jf_ Avatar answered Nov 13 '22 19:11

jf_