简体   繁体   中英

native C++-DLL wrong data on visual studio 2010 and OpenCV

If someone can help me I really appreciate it.

I'll explain the situation in details.

I have a solution with two projects:

  1. project for win32 DLL in unmanaged c++
  2. console application project to test the DLL.

project 1 which creates the dll uses OpenCV library statically linked.

it contains the following class:

class  CData_1D: public cv::Mat // (dllexport/dllimport depending on the project)
{
 unsigned m_length;

 CData_1D(unsigned cn)
 {
 m_length = cn;

 Mat(1, cn, DataType<double>::type);
 }
}

in project 2 main() function:

main()
{
CData_1D TestUnit(10);  
cout << TestUnit.m_length; // 1124007936

}

it compiles and run with no exception, but the data is completely wrong while m_length should be 10, its always 1124007936

I've ommited the rest of the code for clarity purpose, let me know the details I have to give you.

Thank you for your help

"Native c++" does not exist, different compilers produce code that is not APB compatible http://en.wikipedia.org/wiki/Application_binary_interface , which means you cant link to it.

This in my opinion is the main major issue with C++. To resolve the issue re-compile OpenCV with the same compiler.

I'm not certain this is your issue but seems likely.

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