Ask Your Question

Static linking of OpenCV libraries in linux32

asked 2013-10-25 00:42:33 -0600

varunIITD gravatar image

updated 2013-10-25 02:51:23 -0600

berak gravatar image

I am using OpenCV for my project.

I am using eigen faces for face recognition. While compiling the program i use opencv_core, opencv_imgproc, opencv_highgui, opencv_objdetect, opencv_contrib libraries and i link them dynamically prefixing "-l" to each library. But my application needs to create a static executable file whi ch contains all the above libraries.

I found that we can statically link using archives. But i need ".o" files of all libraries to put in archive and then statically link. How can i create .o files of libraries. Presently i have only .so files in /usr/local/lib. Please help me in this matter.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2013-10-25 02:54:30 -0600

berak gravatar image

you can run cmake with "-D BUILD_SHARED_LIBS=OFF" , and then rebuild opencv. this should generate static libs instead of so's.

edit flag offensive delete link more


Thanks berak :) I found that these static libraries(.a files) are generated in /usr/local/lib. Can you let me know how to link these static libraries in g++? Earlier, my command was the following: g++ facerec_save_load_eigen.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_objdetect -lopencv_contrib -o faceRec What is the change that i need to do now?

Thanks a ton for timely and much needed response.

varunIITD gravatar imagevarunIITD ( 2013-10-25 15:51:00 -0600 )edit

whaa, 1 in the night here, an i'm not exactly a linux guru. but i'll promise to think about it tomorrow.

berak gravatar imageberak ( 2013-10-25 17:42:09 -0600 )edit

Thanks buddy !

varunIITD gravatar imagevarunIITD ( 2013-10-26 03:07:12 -0600 )edit

isn't it just " g++ -L /usr/local/lib " (other args remain the same) ?

berak gravatar imageberak ( 2013-10-26 04:09:32 -0600 )edit

ok i will check with that and let u know. Thanks for your help.

varunIITD gravatar imagevarunIITD ( 2013-10-27 01:09:43 -0600 )edit

Actually i need to create static executable. But g++ --static followed by format mentioned by you does not work :( It throws many errors approx 500! Can you help in this matter berak?

varunIITD gravatar imagevarunIITD ( 2013-10-30 14:17:38 -0600 )edit

A lot of them include pthreads, gtk etc..

varunIITD gravatar imagevarunIITD ( 2013-10-30 14:19:42 -0600 )edit

Question Tools


Asked: 2013-10-25 00:42:33 -0600

Seen: 2,503 times

Last updated: Oct 25 '13