Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A cross-platform AnyCPU approach #40

Closed
AndreyAkinshin opened this issue Jul 14, 2014 · 14 comments
Closed

A cross-platform AnyCPU approach #40

AndreyAkinshin opened this issue Jul 14, 2014 · 14 comments
Labels
enhancement New feature or request

Comments

@AndreyAkinshin
Copy link

Hi, in #26 we discussed a problem of AnyCPU support for Windows and Unix. Unfortunately, I could not find a beautiful solution based on the DllImport attribute because of Mono and Microsoft .NET Runtime have different algorithms that work with native libraries. So, I developed own approach: we can generate calls of native method on the fly by signatures from some interface. Please take, a look at my solution: https://github.com/AndreyAkinshin/DotNetRuntimeImplementer
If you like this approach, I can modify it to your needs.

@AndreyAkinshin
Copy link
Author

New version of the library: https://github.com/AndreyAkinshin/InteropDotNet
Also I did cross-platform AnyCPU support for .NET Tesseract wrapper: charlesw/tesseract#107
It really works =)

@shimat
Copy link
Owner

shimat commented Jul 23, 2014

I am sorry for the late reply. Your new solution is so great. Thank you.

I have a question. To use your solution, I understand that release package should be bundled with Win32 library (.dll) and Unix library (.so). I think a .so file that built in Linux probably does not work in BSD. So I have to bundle a package with many library files for all platforms. This is not realistic. Is this understanding mistaken?

In general, Unix platforms have some powerful package managers (e.g. apt, yum, homebrew, ...). For example, the command apt-get install libopencv-dev puts all OpenCV library files to our environment and sets the path to them. So, DllImport can load library file without any care. I think there are few motivation points to distribute *.so library files.

@AndreyAkinshin
Copy link
Author

This is not a problem. I can implement any logic for library name resolving. Please, look to the LoadLibrary method of the LibraryLoader class. That's all we need. So, I can implement new logic myself if you tell me what you want for each platform.

@shimat
Copy link
Owner

shimat commented Jul 24, 2014

I understand the name resolving logic. It is cool.

My fear is that I need to prepare many many OpenCV library files for all platforms on every OpenCV version upgrade. This is a different problem from your system.

By the way, the Mono's DllMap system seems to have name resolving system that is similar to your project.

<configuration>
    <dllmap dll="libc">
        <dllentry dll="libdifferent.so" name="somefunction" target="differentfunction" />
        <dllentry os="solaris,freebsd" dll="libanother.so" name="somefunction" target="differentfunction" />
    </dllmap>
</configuration>

http://www.mono-project.com/Config_DllMap

@AndreyAkinshin
Copy link
Author

My fear is that I need to prepare many many OpenCV library files for all platforms on every OpenCV version upgrade.

Ok, I get it. I think that it is not a problem to use installed opencv library from specific os system folder.

By the way, the Mono's DllMap system seems to have name resolving system that is similar to your project.

I met a problem with native dependences between libraries when I tried apply the DllMap aproach for Tesseract wrapper. If you can use DllMap for OpenCvSharp, it will be so great. In this case you can use DllMap for Mono and WindowsLibraryLoader for MS .NET Runtime. But if you also meet some problems, I am ready to update my InteropDotNet library for you needs.

@AndreyAkinshin
Copy link
Author

Any updates? What is the expected time for Linux support?

@AndreyAkinshin
Copy link
Author

Any updates?

@shimat
Copy link
Owner

shimat commented Sep 11, 2014

I am very sorry for the late reply 🙇

I am sorry but I think it has little significance because Mono's DllMap works fine on my environment (Debian wheezy & MacOSX). DllMap config files are already attached to the OpenCvSharp release packages.

@AndreyAkinshin
Copy link
Author

Ok, I will try it. But now I have some troubles with OpenCvSharpExtern building under Debian. There is an error:

CMake Error at OpenCvSharpExtern/CMakeLists.txt:73 (add_library):
  Cannot find source file:

    CvANN_MLP.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx

What should I do? Can you provide ready binaries of the OpenCvSharpExtern library for popular Linux distributives (like Debian)?

@AndreyAkinshin
Copy link
Author

Debian wheezy — the same problems.

My steps:

  1. Install clear version of Debian wheezy
  2. Install opencv 2.4.9 (via this script: https://github.com/jayrambhia/Install-OpenCV/blob/master/Ubuntu/2.4/opencv2_4_9.sh )
  3. Download last version of OpenCvSharp:
git clone https://github.com/shimat/opencvsharp.git 

to opencvsharp directory.
4. Run

cmake .

from the opencvsharp/src directory.
5. Get the same error:

CMake Error at OpenCvSharpExtern/CMakeLists.txt:73 (add_library):
  Cannot find source file:

    CvANN_MLP.cpp

  Tried extensions .c .C .c++ .cc .cpp .cxx .m .M .mm .h .hh .h++ .hm .hpp
  .hxx .in .txx

What am I doing wrong?

@eAi
Copy link

eAi commented Oct 2, 2014

I'm having the same issue building on OS X 10.9 - I'd love to know what I'm doing wrong as I've been banging my head against this wall for quite a while now!

@shimat
Copy link
Owner

shimat commented Oct 17, 2014

Thank you. The CMake configuration was fixed: 83caebd

@wind39
Copy link

wind39 commented Nov 18, 2014

Please forgive me and correct me if I'm wrong.

This cross-platform approach means my application would have all opencv .so (or .dll, for Windows) files in the bin folder, so the user wouldn't need to install opencv on his machine?

Assuming the size of my application is not an issue, did I get it right? Is there a way to do it with OpenCvSharp?

Thanks in advance! :)

@shimat
Copy link
Owner

shimat commented Dec 14, 2014

I fixed Cmake config problems of OpenCvSharpExtern. (please discuss this issue in #10)

win39> I guess you are right. but I do not know much about shared library in unix.

@shimat shimat closed this as completed Nov 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants