简体   繁体   中英

Problem with WinMain already defined in iup.lib

I'm currently migrating a project from C to C++ and also would like to use cmake for project setup, but I don't know if the issue is actually related to cmake. Unfortunately I have not so much insight into lua details, it's right now just an obstacle for migrating.

I can reproduce the issue with the following sample:

#include <lauxlib.h>
#include <lualib.h>
#include <lua.h>

#include <iup.h>
#include <iuplua.h>
#include <iupcontrols.h>
#include <iupluacontrols.h>

#include <Windows.h>

lua_State *my_lua_init()
{
    lua_State *L;
    L = luaL_newstate();
    luaL_openlibs(L);
    lua_pop(L, 1);
    luaL_register(L, "my_project", NULL);
    lua_pop(L, 1);

    iuplua_open(L);
    iupcontrolslua_open(L);

    return L;
}

void my_lua_close(lua_State *L)
{
    if (L) 
        lua_close(L);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpszCmdLine, int cmdShow)
{
    lua_State *L = my_lua_init();

    my_lua_close(L);
    return 0;
}

and I get the following Linker Errors:

  1. error LNK2005: WinMain already defined in main.obj
  2. error LNK2019: unresolved external symbol main referenced in function WinMain

I use prebuilt static libraries for lua , iup , im_toolkit and canvasdraw for vc16 (VS2019) and 64bit. The application is also build with VS2019 and 64bit.

When I inspect the iup.lib , I indeed see the WinMain as a symbol there.

Now two question came to my mind:

  1. Why does the iup.lib defines a WinMain? Seems strange to me, as it is a library, and not a application.
  2. Is there a workaround to get the application properly linking?

Unfortunately I have to use the WinMain and can not change it to main. I already played around with target_link_libraries order in cmake, but got no working solution yet.

Thanks for help!

EDIT: normal main(...) is working, but that's not an option unfortunately.

int main(int argc, char** argv)
{
    lua_State *L = my_lua_init();

    my_lua_close(L);
    return 0;
}

EDIT2:

With some trial and error I figured out, that the problem seems to be somehow related that lua-related source file is compiled as C++ in the main project, and not C. Nevertheless for the small sample from above the problem occurs in both cases, compiling as C or C++. So it seems to be only halfway of the solution.

IUP defines a WinMain to allow the application to be fully portable by using a "main" declaration instead. So simply use main instead of WinMain, as commented above, but it is not necessary to use "-mconsole".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM