打開samples/01_HelloWorld,你會(huì)發(fā)現(xiàn),只有一個(gè)hello.c和Makefile文件。
打開hello.c,你會(huì)更加吃驚,因?yàn)橹挥?/p>
#include <stdio.h>
int main(int argc, char **argv)
{
printf(“Hello World”);
//這是我加上的,原文沒有。
return 0;
}
這完全就是一個(gè)普普通通的C語言HELLO WORLD程序。
在程序中,夾雜著一段注釋
// flascc comes with a normal BSD libc so everything you would expect to
// be present should work out-of-the-box. This example just shows a
// simple message formatted using printf.
//
// When compiled as a projector this message will be to stdout just like
// a normal commandline application. When compiled to a SWF it will be
// displayed in a textfield on the stage. This behavior is overrideable
// as you will see in later samples.
大概就是說FLASCC使用的是常規(guī)的BSD libc。如果是使用普通的C庫,那你的代碼編寫起來,沒有任何區(qū)別。
使用FLASCC編譯時(shí),可以編譯成三種東西, 一種是Projector程序,這種程序是在Cygwin下可以執(zhí)行的EXE文件。
一種是swf,這種就是直接可以用FP播放的了。 還有一種是SWC,可以提供給AS3調(diào)用。
代碼本身沒有太多特別的。 我們來看看Makefile的內(nèi)容。
T01: check
@echo "-------- Sample 1 --------"
@echo && echo "First let's compile it as a projector:"
"$(FLASCC)/usr/bin/gcc" $(BASE_CFLAGS) hello.c -o hello.exe
@echo && echo "Now lets compile it as a SWF:"
"$(FLASCC)/usr/bin/gcc" $(BASE_CFLAGS) hello.c -emit-swf -swf-size=200x200 -o hello.swf
include ../Makefile.common
clean:
rm -f hello.swf hello *.bc *.exe
這個(gè)Makefile中,第一次是將這個(gè)編譯為hello.exe,即剛剛說到的Projector程序。 第二次是編譯為hello.swf.
可以看出,二者都使用了相同的CFLAGS標(biāo)記。 我們打開Makefile.common可以看到,BASE_CFLAGS實(shí)際上是
-Werror -Wno-write-strings -Wno-trigraphs
我們暫時(shí)不關(guān)注這個(gè)。 我們來看看,如果想生成一個(gè)projector程序,則和GCC下編譯一個(gè)普通的EXE程序沒有區(qū)別。而如果是想編譯為SWF,則需要手動(dòng)指定一些額外的參數(shù)。
-emit-swf -swf-size=200x200
-emit-swf表示告訴編譯器,目標(biāo)文件是swf
-swf-size=200x200則告訴編譯器,最終生成的目標(biāo)SWF的舞臺(tái)大小。
總的來說,這個(gè)比較簡單,雖然沒有什么可看的。還是貼一下效果圖。
