Using boost threads when compiling with /clr

耗尽温柔 提交于 2019-12-17 21:08:45

问题


I have gave up on creating a GUI directly from the windows API so I'm going to use forms. I would like to multithread my app and wrap the GUI in a class and put it in a separate thread. When I click a button, etc, it would change a value in a struct that will be read from the main thread. My problem is, when I compile my application I get an error with the linker.

1>Core.obj : error LNK2022: metadata operation failed (8013119F) : A TypeRef exists which should, but does not, have a corresponding TypeDef: (dummy): (0x0100001f).

My code for main is as follows.

int main()
{
//create thread object pointer
    boost::thread *GUIThread;
//create pointer to GUIInterface, which contains a member function that
//contains the Application::Run
    GUIInterface *myinterface;
    myinterface = new GUIInterface;

    GUIThread = new boost::thread(boost::bind(&GUIInterface::MainFunction, myinterface));
    return 0;
}

It works fine when creating the class and calling the function in the main thread, but using boost causes problems. I built boost using the correct compiler MSVC-10.0 and the threading library has always worked in the past, but clr just causes problems. Any recommendations on how to fix this? OR if I should just use .net multithreading(if I do, I really need some links to how to use in with c++, most stuff I find is in C#). Thanks.


回答1:


There are two problems when using boost::thread in a managed application. The first is the linker error you encountered. The second is an initialization error at application startup if the boost::thread implementation is statically linked with your application.

Both problems are mentioned in an older bug report. I don't know if this has changed in later releases; 1.43 has the same problem. I assume not as the case was closed wontfix.



来源:https://stackoverflow.com/questions/4649960/using-boost-threads-when-compiling-with-clr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!