Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
497 views
in Technique[技术] by (71.8m points)

.net - Using boost threads when compiling with /clr

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...