我可以修改和编译SDK的stringecho.c示例,AS3使用没问题。
对于我自己的应用程序,我使用g ++成功编译了几十个文件并链接:
g++ -swc -o myApp.swc glue.o demo.o obj1.o obj2.o obj3.o
我确实得到了一个myApp.swc,但错误的只有80k(与简单的stringecho示例大小相同)。
在任何Flash IDE中进行检查时,与具有
的stringecho.swc不同cmodule.stringecho.AlchemyBlock
cmodule.stringecho.AlchemyBreakPoint
...
这个myApp.swc有
cmodule.AlchemyBlock
cmodule.AlchemyBreakPoint
...
并没有我定义的胶水功能。实质上,我不能在AS3项目中使用它。
我的glue.c代码如下。基本上,我创建一个演示对象并调用它的函数。演示类封装了所有其他目标文件。
#include "demo.h"
#include "AS3.h"
AS3_Val InitSystem(void* self, AS3_Val args)
{
demo = new demo9();
return 0;
}
AS3_Val LoadSceneFile( void* self, AS3_Val args )
{
demo->loadScene("scene.txt");
return 0;
}
...
int main()
{
AS3_Val InitSystemMethod = AS3_Function( NULL, InitSystem );
AS3_Val LoadSceneFileMethod = AS3_Function( NULL, LoadSceneFile );
AS3_Val getAlchemyScreenMethod = AS3_Function( NULL, getAlchemyScreen );
AS3_Val setMouseStateMethod = AS3_Function( NULL, setMouseState );
AS3_Val rasterizeMethod = AS3_Function( NULL, rasterize );
AS3_Val result = AS3_Object("InitSystem: AS3ValType,LoadSceneFile: AS3ValType,getAlchemyScreen:AS3ValType,setMouseState:AS3ValType,rasterize:AS3ValType"
,InitSystemMethod,
LoadSceneFileMethod,
getAlchemyScreenMethod,
setMouseStateMethod,
rasterizeMethod);
AS3_Release( InitSystemMethod );
AS3_Release( LoadSceneFileMethod );
AS3_Release( getAlchemyScreenMethod );
AS3_Release( setMouseStateMethod );
AS3_Release( rasterizeMethod );
AS3_LibInit( result );
return 0;
}
答案 0 :(得分:1)
阅读此blog post。
简短的说法是链接大量的.o文件是行不通的。您需要将它们“ar”在一起成为库(.a)文件。然后针对该库编译胶水代码。根据你的例子,它将是这样的:
ar rc mylib.a demo.o obj1.o obj2.o obj3.o
ranlib mylib.a
g++ -swc -o myApp.swc glue.c mylib.a