Generating a shared library of a project in c ++ with OpenCV


I have a C ++ code in visual study in which I use OpenCV to perform certain functions. So far I have had to generate a DLL to integrate it into Unity, but now I have to create a .so to integrate it into Unity and then create an Android application. The truth is that I can not find a way to do it.

And another question, I have compiled the OpenCV source code with CMake in DLL libraries, how do I generate the .so?

asked by Urko Sanchez Ortiz 29.09.2017 в 12:19

1 answer


You have a compilation problem. If you create an ad-hoc project on Visual Studio, this will generate libraries and executables with the VS compiler in its output formats (Static library: .lib, Dynamic library: .dll, Executable: .exe)

Android is an operating system derived from GNU / Linux, the formats are different, so the compiler generates different output files (Static library: .a, Dynamic library: .so, Executable: .bin). Note: The files do not need to have. to work as if it is necessary in Windows.

As you rightly point out in your second question, what you need is to use CMake to generate these files. Since you are on a Windows computer, and your library has a different target (in this case Android), you need to use a TOOLCHAIN to be able to compile the source files with the output in the desired format. It is perfectly documented in the CMake reference . There is an Android toolchain in the network maintained by OpenCV here .

If you use CMake loading the toolchain, and you have written the source code with standard libraries, you should directly generate the files you need. If the compiler gives you an error, then you'll have to support both compilers with the source.

answered by 30.10.2017 / 15:54