FlasCC例子研究之HelloWorld

打开samples/01_HelloWorld,你会发现,只有一个hello.c和Makefile文件。

打开hello.c,你会更加吃惊,因为只有

#include <stdio.h>

int main(int argc, char **argv)
{
    printf(“Hello World”);
    //这是我加上的,原文没有。
    return 0;
}

这完全就是一个普普通通的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使用的是常规的BSD libc。如果是使用普通的C库,那你的代码编写起来,没有任何区别。

使用FLASCC编译时,可以编译成三种东西, 一种是Projector程序,这种程序是在Cygwin下可以执行的EXE文件。

一种是swf,这种就是直接可以用FP播放的了。 还有一种是SWC,可以提供给AS3调用。

代码本身没有太多特别的。 我们来看看Makefile的内容。

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

这个Makefile中,第一次是将这个编译为hello.exe,即刚刚说到的Projector程序。 第二次是编译为hello.swf.

可以看出,二者都使用了相同的CFLAGS标记。 我们打开Makefile.common可以看到,BASE_CFLAGS实际上是

-Werror -Wno-write-strings -Wno-trigraphs

我们暂时不关注这个。 我们来看看,如果想生成一个projector程序,则和GCC下编译一个普通的EXE程序没有区别。而如果是想编译为SWF,则需要手动指定一些额外的参数。

-emit-swf -swf-size=200x200

-emit-swf表示告诉编译器,目标文件是swf

-swf-size=200x200则告诉编译器,最终生成的目标SWF的舞台大小。

总的来说,这个比较简单,虽然没有什么可看的。还是贴一下效果图。

image

原文地址:https://www.cnblogs.com/qilinzi/p/3077010.html