Boost logo

Threads-Devel :

Subject: [Threads-devel] [thread] LNK2022 error in VisualStudio 2008 (VC9) C++/CLR code
From: Matt Schuckmann (matt_at_[hidden])
Date: 2009-11-03 11:45:54


I'm not fully sure if this is a Microsoft problem or a boost problem but
here goes.

I'm using boost 1.37.0, ( I haven't tested yet but I believe the problem
will exist with 1.40.0 too)
The code below compiles and links fine if the /clr switch is off but
gives a LNK2022 error if it is turned on. The project is a CLR/C++ Class
Library (i.e. .NET DLL)

Error I'm seeing is:
ClassLibrary_test.obj : error LNK2022: metadata operation failed
(8013119F) : A TypeRef exists which should, but does not, have a
corresponding TypeDef: (dummy): (0x0100001c).

And it appears that the problem has to do with "struct dummy;"
declaration on line 144 of boost/thread/detail/thread.hpp. Apparently
the CLR compiler can't deal with an empty undefined struct type even
thow I've told the compiler to treat all of it as unmanaged code.

Can anyone make any suggestions on how to fix this?

Thanks,
Matt Schuckmann

File ClassLibrary.h:
--------------------------------------
// ClassLibrary_test.h

#pragma once

namespace ClassLibrary_test {

#if defined(_MANAGED)
public ref class Class1
#else
class Class1
#endif
   {
   Class1();
   };
}
-------------------------------------

File ClassLibrary.cpp
----------------------------------------------
#include "ClassLibrary_test.h"

#pragma managed(push, off)
#include <boost/thread/recursive_mutex.hpp>
#include <boost/thread/condition.hpp>
#include <boost/thread/thread.hpp>
//#pragma managed(pop)
class MyTest
{
protected:
 boost::condition condition;
   boost::mutex mutex;

public:
 void wait()
 {
   boost::mutex::scoped_lock lock(mutex);
   condition.wait(lock);
 }

 void notify()
 {
   condition.notify_all();
 }
};

class MyThread
{
public:
 MyThread( MyTest& tst )
   : t(tst)
 {}

protected:
  MyTest& t;
public:
 void operator()()
 {
   this->t.notify();
 }
};

#pragma managed(pop)

ClassLibrary_test::Class1::Class1()
{
  MyTest t;
  MyThread thrd(t);
  boost::thread temp(thrd);

  t.wait();

}
---------------------------------------------


Threads-Devel list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk