最近我将opencv构建为静态库(使用BUILD_SHARED_LIBS = OFF),而动态库已经存在,但位于不同的位置。当我构建可能程序时,我收到很多错误。我正在使用命令行来编译代码,如下所示。
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
错误看起来像,
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'
答案 0 :(得分:1)
这些错误不是来自OpenCV(从函数名称可以看出),而是来自GLib和libpthread。使用-lglib-2.0 -lpthread
链接器标志。