2012年10月24日 星期三

Passing string as -D compiler flag to .c

有時候有些字串需要compiler time時決定。通常前期先用menuconfig之類的工具設定好,再進行compile動作,此時新字串就會自動帶進.c中。

要做到這樣的效過,在gcc中可以用-D方式指定。

gcc編譯中加入 -DNEW_STRING=\"xxxxxxx\"。

在c原始碼內,利用一些字串連接的技巧串起來。或者可以自己加入#define中。

char a* = "I got "NEW_STRING"!!!!";

這樣目的就達成了。


參考資料
[1] Passing string as -D compiler option