- 论坛徽章:
- 0
|
use gcc in shell script
原帖由 "kfcn" 发表:
Hi, Red Sleeve or other high hands;
I still have the problem of changing the value of the variable in the c file. Say, the file is soso.c, the variable is cHANGEABLE, I want the value of cHANGEAB..........
okay, i understand what you want.
there are probably some syntax errors or undefined variables in your C code.
1. there should be a hash before define, i.e. #define
2. since quesheng is a string, it should be quoted
try this one, assume it's called soso.c
- #include <stdio.h>
- #ifndef cHANGEABLE
- #define cHANGEABLE "quesheng"
- #endif
- int main()
- {
- char* var = cHANGEABLE ;
- printf("cHANGEABLE is: %s\n", var);
- return(0);
- }
复制代码
then your script 'changeit' may look like this,
- if [ x"$1" = x ]; then
- var="quesheng"
- else
- var=$1
- fi
- echo "the executable file is: $var"
- gcc -DcHANGEABLE=\"$var\" -o $var soso.c
复制代码
tested on Solaris and IRIX,
sleeve@sievert:~[503]$ ./changeit xingle
the executable file is: xingle
sleeve@sievert:~[504]$ ls -l xingle
-rwx------ 1 sleeve other 5875 Jun 27 18:06 xingle
sleeve@sievert:~[505]$ ./xingle
cHANGEABLE is: xingle
sleeve@sievert:~[506]$ ./changeit
the executable file is: quesheng
sleeve@sievert:~[507]$ ./quesheng
cHANGEABLE is: quesheng
sleeve@sievert:~[508]$
hope it helps. |
|