Anirudh
Anirudh

Reputation: 874

How to compile a standalone OpenCV executable?

I compile my my OpenCV programs as follows:

g++ `pkg-config --cflags opencv --libs opencv` <filename>.cpp

It works perfectly on my computer. Can I complile the shared libraries alone with the program so that it can be run on other computers which doesnt have opencv on it? If so, how do I do it?

Upvotes: 6

Views: 5526

Answers (3)

Anirudh
Anirudh

Reputation: 874

The program during compilation are dynamically linked to Shared Libraries (.so files) on our computer. The executable compiled use these shared libraries during run-time. But these shared libraries may not be present on other computers, hence might not be able to run the executable.

Solution to this will be to statically link Archive Libraries (.a files) instead of dynamically linking Shared Libraries. OpenCV does not distribute archive libraries as such. So one will have to compile archive library from the its source using cmake -DBUILD_SHARED_LIBS=OFF. This archive library can be used to create standalone executable.

Upvotes: 2

lynxlynxlynx
lynxlynxlynx

Reputation: 1433

Yes to some degree: lookup static linking. Your opencv copy must have .a versions of the libraries (not just .so you mention) and that is also true for any other dependencies.

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 799210

No. You need to use static libraries.

Upvotes: -1

Related Questions