Tiny C 编译器:未定义的符号“main” main 是什么时候定义的?

发布于 2024-12-12 18:15:30 字数 2075 浏览 1 评论 0原文

我有一个 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: %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);
}

编辑:我通过 tcc 运行代码,仅进行预处理。显然,通过 SDL 中的一些宏,main 函数被重命名为 SDL_main。

I have a main function, but when tcc goes to link everything together, it says its undefined. Why is this?

I'm using a python build script, and arguments are passed as lists:

['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']

The output is simply:

tcc: undefined symbol 'main'

My main function is defined in the file main.c (and doesn't have a header), with a couple of static functions.
Main function:

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: %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);
}

EDIT: I ran the code through tcc with preprocessing only. Apparently the main function is being renamed to SDL_main, through some macro in SDL.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

晨敛清荷 2024-12-19 18:15:30

-lSDLmain 添加到链接器标志。

http://wiki.libsdl.org/moin.cgi/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22

尽管 tcc 中的情况可能略有不同。

Add -lSDLmain to linker flags.

http://wiki.libsdl.org/moin.cgi/FAQWindows#I_get_.22Undefined_reference_to_.27WinMain.4016.27.22

Although things may be a little different in tcc.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文