Note that there are some explanatory texts on larger screens.

plurals
  1. POTiny C Compiler: Undefined symbol "main" when main is defined?
    text
    copied!<p>I have a main function, but when tcc goes to link everything together, it says its undefined. Why is this?</p> <p>I'm using a python build script, and arguments are passed as lists:</p> <pre><code>['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'] </code></pre> <p>The output is simply:</p> <pre><code>tcc: undefined symbol 'main' </code></pre> <p>My main function is defined in the file main.c (and doesn't have a header), with a couple of static functions. Main function:</p> <pre><code>int main(int argc, char *argv[]) { SDL_Surface* screen = render_initialize(1024,768); lua_State* L = luaL_newstate(); //lua_atpanic(L,&amp;Lpanic); msL_registerState(L); msL_openAllLibs(L); int fail = luaL_dofile(L,"lua/main.luac"); if(fail) { fprintf(stderr, "Lua error: %s\n", 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 scope\n"); 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); } </code></pre> <p><strong>EDIT:</strong> I ran the code through tcc with preprocessing only. Apparently the main function is being renamed to SDL_main, through some macro in SDL.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload