Ask Your Question
0

compile static openCV library

asked 2017-01-13 20:25:54 -0600

sknelson111 gravatar image

updated 2017-01-14 14:29:38 -0600

Hi,

I'd like to compile my program with openCV as a static library, to create a standalone app. I've tried using the cmake flag BUILD_SHARED_LIBS=OFF, however when I try to run my app on an ubuntu machine without openCV installed, I get the following error:

./gray_static_v03.out: error while loading shared libraries: libpng12.so.0: cannot open shared object file: No such file or directory

Here is a link to the dockerfile - where you can see my install commands: github.com/sknelson111/openCV/blob/master/Dockerfile

and here is the command I use to compile:

g++ -o gray.out gray.cpp `pkg-config opencv --cflags --libs --static`

Any ideas what I am doing wrong? Any help would be greatly appreciated!

Thank you!

edit retag flag offensive close merge delete

Comments

also, please use opencv3.2, not 3.0

berak gravatar imageberak ( 2017-01-14 04:26:52 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-01-14 04:31:08 -0600

berak gravatar image

updated 2017-01-14 12:50:37 -0600

i'm not sure, if you really want to go without any png support, but for statically linking, without any assumptions about libraries available on the final host machine you either need:

-DBUILD_PNG=OFF -DWITH_PNG=OFF   //disable png entirely

or:

-DBUILD_PNG=ON -DWITH_PNG=ON     //link in libpng statically from 3rdparty folder

same pattern also applies to JPG, and TIFF !

edit flag offensive delete link more

Comments

1

Thanks for your reply Berak. I think I see now that I need to build all the dependencies statically as well, that was probably my problem. So I will give it a shot - and if I have more questions I will let you know. Thank you!

sknelson111 gravatar imagesknelson111 ( 2017-01-14 15:22:54 -0600 )edit

oh, I'm sorry, I see what you were saying. Yeah, added -DBUILD_PNG=ON -DWITH_PNG=ON and everything is working now. Thank you so much!

sknelson111 gravatar imagesknelson111 ( 2017-01-14 17:17:56 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-01-13 20:25:54 -0600

Seen: 1,989 times

Last updated: Jan 14 '17