我有一个main函数,但是当tcc将所有内容链接在一起时,它说它未定义。为什么会这样?
我正在使用python构建脚本,参数作为列表传递:
['v:/exe/tcc/tcc.exe', '-odist/***.exe', '-Llib/', '-llua5.1', '-lsoil', '-lSDL', '-lopengl32', 'build/luainterface\msL.o', 'build/luainterface\vector.o', 'build/rendering\renderutil.o', 'build/structures\crtree.o', 'build/structures\uniqueid.o', 'build/structures\vector.o', 'build/world\blocklib.o', 'build/world\chunk.o', 'build/world\world.o', 'build/main.o']
输出很简单:
tcc: undefined symbol 'main'
我的main函数是在文件main.c中定义的(并且没有头文件),还有几个静态函数。主要功能:
int main(int argc, char *argv[])
{
SDL_Surface* screen = render_initialize(1024,768);
lua_State* L = luaL_newstate();
//lua_atpanic(L,&Lpanic);
msL_registerState(L);
msL_openAllLibs(L);
int fail = luaL_dofile(L,"lua/main.luac");
if(fail)
{
fprintf(stderr, "Lua error: %sn", lua_tostring(L,-1));
doexit(1);
}
lua_getfield(L,LUA_GLOBALSINDEX,"draw");
if(!lua_isfunction(L,-1))
{
lua_pop(L,1);
fprintf(stderr, "No draw function defined in global scopen");
doexit(1);
}
lua_setfield(L,LUA_REGISTRYINDEX,"msL_drawfunction");
while(1)
{
lua_getfield(L,LUA_REGISTRYINDEX,"msL_drawfunction");
assert(lua_isfunction(L,-1));
int err = lua_pcall(L,0,0,0);
if(err)
{
fprintf(stderr,"Lua error: ");
switch(err)
{
case LUA_ERRRUN:
fprintf(stderr,"%s",lua_tostring(L,-1));
break;
case LUA_ERRMEM:
fprintf(stderr,"out of memory");
break;
default:
fprintf(stderr,"unknown error");
}
fprintf(stderr,"n");
doexit(1);
}
render_flipbuffers(screen);
}
doexit(0);
}
EDIT:我通过tcc运行代码,只进行预处理。显然,main函数通过SDL中的一些宏被重命名为SDL_main。
将-lSDLmain
添加到链接标志中
http://wiki.libsdl.org/moin.cgi/FAQWindows I_get_.22Undefined_reference_to_.27WinMain.4016.27.22
尽管在tcc中情况可能略有不同