简体   繁体   中英

How to build the whole openCV library into a static library?

I would like to build the whole openCV library into a file like opencv.a. I'm trying to use the.a binary file to link together with cpp code that I made that uses the openCV library, using emscripten to make a single wasm file.

Basically what I want to do is to compile the cpp app I made that uses the openCV library into webassembly so that I can run it in a browser. I read on other posts that the way to do it is to get openCV as aa file and then link it with my cpp code using emscripten.

A detailed explanation of how to produce the.a file will be much appreciated. Please understand that I'm not a cpp developer and I'm clueless about using build tools that complile it.

Thanks.

Building OpenCV static libs

I think that is possible to build the whole OpenCV libs as a big static lib. But it is highly recommended to build the single and separated static libs for a fined granulated comiplation. There are also parts of OpenCV project that compiling with Emscripten are very hard to build. And what about if you want use only a set of OpenCV functions? The final.js or.wasm file will be too big.

Example opencv-em

We did this script opencv-em to build a set of static libs that we need for a project. It build the static libs and pack the needed include directories.

Step build description

We have set up a shell build script. We used cmake for the compilation because the existent CMakeLists.txt in the OpenCV project directory, this simplify things a lot:

 cmake .. -GNinja -DCMAKE_TOOLCHAIN_FILE=$EM_TOOLCHAIN $OPENCV_CONF $OPENCV_INTRINSICS -DCMAKE_CXX_FLAGS="$EM_FLAGS" -DCMAKE_C_FLAGS="$EM_FLAGS"

we used Ninja as a compiler but you can use make.

-DCMAKE_TOOLCHAIN_FILE=$EM_TOOLCHAIN

This define the toolchain in this case Emscripten:

EM_TOOLCHAIN="$EMSCRIPTEN/cmake/Modules/Platform/Emscripten.cmake"

You need of course to install Emscripten with emsdk .

OPENCV_CONF is the variable where you define which libs to build and the necessary files to include and to exclude (that is very important!) Note also that compilation may vary in base of Emscripten and OpenCV version!

Downloads

If you want you can downloads the libs in the releases page. Read the Emscripten and OpenCV version used.

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