Haris
Haris

Reputation: 14053

Opencv Static Linking Gives Error

Recently I build opencv as static library(by using BUILD_SHARED_LIBS=OFF) while dynamic libraries are already there, but at different location. And when I build may program I am getting many error. I am using command line for compiling the code, and look like below.

g++ -static -I$(OpenCV_Static_Build)/include/opencv -L$(OpenCV_Static_Build)/lib/ -g -o binary  main.cpp -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy

The error look like,

grfmt_tiff.cpp:(.text._ZN2cv11TiffEncoder12writeLibTiffERKNS_3MatERKSt6vectorIiSaIiEE+0x167): undefined reference to `TIFFSetField'
window_gtk.cpp:(.text.cvNamedWindow+0x29d): undefined reference to `g_type_check_instance_cast'
/usr/lib/gcc/i486-linux-gnu/4.4.3/libgcc_eh.a(unwind-dw2.o): In function `uw_init_context_1':
(.text+0x22f8): undefined reference to `pthread_once'

Upvotes: 0

Views: 732

Answers (1)

user529758
user529758

Reputation:

Those errors don't come from OpenCV (as one can tell from the function names) but from GLib and libpthread. Use the -lglib-2.0 -lpthread linker flags.

Upvotes: 1

Related Questions