2

I have a static library (native c++).

Now I would like to use this static library in a C++/CLi project.

Compiling is ok, but there is a runtime error saying "ntdll.dll! ****memory access violation".

Both the static library and the clr project are using "/MD".

Is it valid to link a clr project to a native c++ static lib? If yes, any special configurations I should pay attention to?

PS. I can't turn the static lib to dll.

Yoh
  • 199
  • 1
  • 13
  • 1
    It's likely some code is not being managed properly hence the access violation, possibly a marshaled string... Could be anything though – Niall Feb 17 '16 at 10:06
  • @Niall Thank you for replying. So nothing is wrong to link a clr project to a static c++ lib. It seems the program throws before it hits any of my own code.(according to the call stack) – Yoh Feb 17 '16 at 14:30
  • I've never tried it; reduce the code to just a single empty function in the static library, build it, test it; then start to add code back, bit by bit. It could still be some static variable initialisation code that causes the issue. – Niall Feb 17 '16 at 15:03
  • I think it may be caused by boost.threading. – Yoh Feb 17 '16 at 15:16
  • 1
    I'm not sure how, or if, boost and the CLI mix. You may need to custom build or provide some custom functionality. – Niall Feb 17 '16 at 15:18

1 Answers1

2

Linking boost::thread dynamically solves this problem.

#define BOOST_THREAD_DYN_LINK

thanks to Using boost in CLR

Community
  • 1
  • 1
Yoh
  • 199
  • 1
  • 13