Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Bundling OpenCV as a static library gives thousands of undefined references

I am working on Ubuntu 14.04 and i want to build OpenCV(4.1.0) as static lib and create a sample program. Building OpenCV works flawlessly but i get thousands of errors when i run the test application.

Building OpenCV:

  • configure cmake:

    cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D BUILD_SHARED_LIBS=OFF -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.0/modules -D CMAKE_INSTALL_PREFIX=/usr/local/opencv ..

  • build:

    make -j8

  • install:

    sudo make install

  • pkg-config setup:

    sudo cp unix-install/opencv4.pc /usr/lib/x86_64-linux-gnu/pkgconfig/

Sample Program

<figure><figcaption>TestApp.cpp</figcaption>
#include <stdio.h>
#include <opencv2/opencv.hpp>
int main( int argc, char** argv )
{
  cv::Mat testmat;
  printf("Test\n");
  return 0;
} 
</figure>
  • build:

    g++ TestApp.cpp -o TestApp `pkg-config --cflags --libs opencv4`

    • I get these errors: Full Console.log > In function > `cvImageWidget_class_init(void, > void)&apos;: > window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0xa): > undefined reference to > `gtk_widget_get_type&apos; > window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x15): > undefined reference to > `g_type_class_peek&apos; > window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x20): > undefined reference to > `g_type_check_class_cast&apos; > /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): > In function > `icvOnTrackbar(_GtkWidget, > void)&apos;: > window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0xd): > undefined reference to > `gtk_range_get_type&apos; > window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x18): > undefined reference to > `g_type_check_instance_cast&apos; > window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x20): > undefined reference to > `gtk_range_get_value&apos; > /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): > In function > `std::_Sp_counted_ptr_inplace&lt;CvWindow, > std::allocator&lt;CvWindow&gt;, > (__gnu_cxx::_Lock_policy)2&gt;::_M_dispose()&apos;: > window_gtk.cpp:(.text._ZNSt23_Sp_counted_ptr_inplaceI8CvWindowSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt23_Sp_counted_ptr_inplaceI8CvWindowSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x12): undefined reference to > `gtk_widget_destroy&apos; > /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): > In function > `icvWindowThreadLoop(void)&apos;: > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x41): > undefined reference to > `gtk_main_iteration_do&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x53): > undefined reference to > `g_usleep&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x58): > undefined reference to > `g_thread_yield&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x113): > undefined reference to > `gtk_main_iteration_do&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x11d): > undefined reference to > `g_usleep&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x122): > undefined reference to > `g_thread_yield&apos; > /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): > In function > `cvImageWidget_size_request(_GtkWidget, > _GtkRequisition*)&apos;: window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x19): > undefined reference to > `gtk_widget_get_type&apos;

I would be thankful for any help.

Bundling OpenCV as a static library gives thousands of undefined references

I am working on Ubuntu 14.04 and i want to build OpenCV(4.1.0) as static lib and create a sample program. Building OpenCV works flawlessly but i get thousands of errors when i run the test application.

Building OpenCV:

  • configure cmake:

    cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D BUILD_SHARED_LIBS=OFF -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.0/modules -D CMAKE_INSTALL_PREFIX=/usr/local/opencv ..

  • build:

    make -j8

  • install:

    sudo make install

  • pkg-config setup:

    sudo cp unix-install/opencv4.pc /usr/lib/x86_64-linux-gnu/pkgconfig/

Sample Program

<figure><figcaption>TestApp.cpp</figcaption>
#include <stdio.h>
#include <opencv2/opencv.hpp>
int main( int argc, char** argv )
{
  cv::Mat testmat;
  printf("Test\n");
  return 0;
} 
</figure>
  • build:

    g++ TestApp.cpp -o TestApp `pkg-config --cflags --libs opencv4`

    • I get these errors: Full Console.log > In function > `cvImageWidget_class_init(void, > void)&apos;: > window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0xa): > undefined reference to > `gtk_widget_get_type&apos; > window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x15): > undefined reference to > `g_type_class_peek&apos; > window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x20): > undefined reference to > `g_type_check_class_cast&apos; > /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): > In function > `icvOnTrackbar(_GtkWidget, > void)&apos;: > window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0xd): > undefined reference to > `gtk_range_get_type&apos; > window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x18): > undefined reference to > `g_type_check_instance_cast&apos; > window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x20): > undefined reference to > `gtk_range_get_value&apos; > /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): > In function > `std::_Sp_counted_ptr_inplace&lt;CvWindow, > std::allocator&lt;CvWindow&gt;, > (__gnu_cxx::_Lock_policy)2&gt;::_M_dispose()&apos;: > window_gtk.cpp:(.text._ZNSt23_Sp_counted_ptr_inplaceI8CvWindowSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt23_Sp_counted_ptr_inplaceI8CvWindowSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x12): undefined reference to > `gtk_widget_destroy&apos; > /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): > In function > `icvWindowThreadLoop(void)&apos;: > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x41): > undefined reference to > `gtk_main_iteration_do&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x53): > undefined reference to > `g_usleep&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x58): > undefined reference to > `g_thread_yield&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x113): > undefined reference to > `gtk_main_iteration_do&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x11d): > undefined reference to > `g_usleep&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x122): > undefined reference to > `g_thread_yield&apos; > /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): > In function > `cvImageWidget_size_request(_GtkWidget, > _GtkRequisition*)&apos;: window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x19): > undefined reference to > `gtk_widget_get_type&apos;

I would be thankful for any help.

Bundling OpenCV as a static library gives thousands of undefined references

I am working on Ubuntu 14.04 and i want to build OpenCV(4.1.0) as static lib and create a sample program. Building OpenCV works flawlessly but i get thousands of errors when i run the test application.

Building OpenCV:

  • configure cmake:

    cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D BUILD_SHARED_LIBS=OFF -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.0/modules -D CMAKE_INSTALL_PREFIX=/usr/local/opencv ..

  • build:

    make -j8

  • install:

    sudo make install

  • pkg-config setup:

    sudo cp unix-install/opencv4.pc /usr/lib/x86_64-linux-gnu/pkgconfig/

Sample Program

#include <stdio.h>
#include <opencv2/opencv.hpp>
int main( int argc, char** argv )
{
  cv::Mat testmat;
  printf("Test\n");
  return 0;
} 
  • build:

    g++ TestApp.cpp -o TestApp `pkg-config --cflags --libs opencv4`

    • I get these errors: Full Console.log > In function > `cvImageWidget_class_init(void, > void)&apos;: > window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0xa): > undefined reference to > `gtk_widget_get_type&apos; > window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x15): > undefined reference to > `g_type_class_peek&apos; > window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x20): > undefined reference to > `g_type_check_class_cast&apos; > /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): > In function > `icvOnTrackbar(_GtkWidget, > void)&apos;: > window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0xd): > undefined reference to > `gtk_range_get_type&apos; > window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x18): > undefined reference to > `g_type_check_instance_cast&apos; > window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x20): > undefined reference to > `gtk_range_get_value&apos; > /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): > In function > `std::_Sp_counted_ptr_inplace&lt;CvWindow, > std::allocator&lt;CvWindow&gt;, > (__gnu_cxx::_Lock_policy)2&gt;::_M_dispose()&apos;: >

/usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `cvImageWidget_class_init(void*, void*)&apos;: window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0xa): undefined reference to `gtk_widget_get_type&apos; window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x15): undefined reference to `g_type_class_peek&apos; window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x20): undefined reference to `g_type_check_class_cast&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `icvOnTrackbar(_GtkWidget*, void*)&apos;: window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0xd): undefined reference to `gtk_range_get_type&apos; window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x18): undefined reference to `g_type_check_instance_cast&apos; window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x20): undefined reference to `gtk_range_get_value&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `std::_Sp_counted_ptr_inplace&lt;CvWindow, std::allocator&lt;CvWindow&gt;, (__gnu_cxx::_Lock_policy)2&gt;::_M_dispose()&apos;: window_gtk.cpp:(.text._ZNSt23_Sp_counted_ptr_inplaceI8CvWindowSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt23_Sp_counted_ptr_inplaceI8CvWindowSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x12): undefined reference to > `gtk_widget_destroy&apos; > /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): > In function > `icvWindowThreadLoop(void)&apos;: > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x41): > undefined reference to > `gtk_main_iteration_do&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x53): > undefined reference to > `g_usleep&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x58): > undefined reference to > `g_thread_yield&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x113): > undefined reference to > `gtk_main_iteration_do&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x11d): > undefined reference to > `g_usleep&apos; > window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x122): > undefined reference to > `g_thread_yield&apos; > /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): > In function > `cvImageWidget_size_request(_GtkWidget, > to `gtk_widget_destroy&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `icvWindowThreadLoop(void*)&apos;: window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x41): undefined reference to `gtk_main_iteration_do&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x53): undefined reference to `g_usleep&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x58): undefined reference to `g_thread_yield&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x113): undefined reference to `gtk_main_iteration_do&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x11d): undefined reference to `g_usleep&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x122): undefined reference to `g_thread_yield&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `cvImageWidget_size_request(_GtkWidget*, _GtkRequisition*)&apos;: window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x19): > undefined reference to > `gtk_widget_get_type&apos;

window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x19): undefined reference to `gtk_widget_get_type&apos; window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x47): undefined reference to `g_type_register_static_simple&apos; window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x5b): undefined reference to `g_type_check_instance_cast&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `cvImageWidget_set_size(_GtkWidget*, int, int)&apos;: window_gtk.cpp:(.text._ZL22cvImageWidget_set_sizeP10_GtkWidgetii+0x19): undefined reference to `gtk_widget_get_type&apos; window_gtk.cpp:(.text._ZL22cvImageWidget_set_sizeP10_GtkWidgetii+0x47): undefined reference to `g_type_register_static_simple&apos;

I would be thankful for any help.

Bundling OpenCV as a static library gives thousands of undefined references

I am working on Ubuntu 14.04 and i want to build OpenCV(4.1.0) as static lib and create a sample program. Building OpenCV works flawlessly but i get thousands of errors when i run the test application.

Building OpenCV:

  • configure cmake:

    cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D BUILD_SHARED_LIBS=OFF -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.0/modules -D CMAKE_INSTALL_PREFIX=/usr/local/opencv ..

  • build:

    make -j8

  • install:

    sudo make install

  • pkg-config setup:

    sudo cp unix-install/opencv4.pc /usr/lib/x86_64-linux-gnu/pkgconfig/

Sample Program

#include <stdio.h>
#include <opencv2/opencv.hpp>
int main( int argc, char** argv )
{
  cv::Mat testmat;
  printf("Test\n");
  return 0;
} 
  • build:

    g++ TestApp.cpp -o TestApp `pkg-config --cflags --libs opencv4`

/usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `cvImageWidget_class_init(void*, void*)&apos;: window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0xa): undefined reference to `gtk_widget_get_type&apos; window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x15): undefined reference to `g_type_class_peek&apos; window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x20): undefined reference to `g_type_check_class_cast&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `icvOnTrackbar(_GtkWidget*, void*)&apos;: window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0xd): undefined reference to `gtk_range_get_type&apos; window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x18): undefined reference to `g_type_check_instance_cast&apos; window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x20): undefined reference to `gtk_range_get_value&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `std::_Sp_counted_ptr_inplace&lt;CvWindow, std::allocator&lt;CvWindow&gt;, (__gnu_cxx::_Lock_policy)2&gt;::_M_dispose()&apos;: window_gtk.cpp:(.text._ZNSt23_Sp_counted_ptr_inplaceI8CvWindowSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt23_Sp_counted_ptr_inplaceI8CvWindowSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x12): undefined reference to `gtk_widget_destroy&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `icvWindowThreadLoop(void*)&apos;: window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x41): undefined reference to `gtk_main_iteration_do&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x53): undefined reference to `g_usleep&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x58): undefined reference to `g_thread_yield&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x113): undefined reference to `gtk_main_iteration_do&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x11d): undefined reference to `g_usleep&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x122): undefined reference to `g_thread_yield&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `cvImageWidget_size_request(_GtkWidget*, _GtkRequisition*)&apos;: window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x19): undefined reference to `gtk_widget_get_type&apos; window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x47): undefined reference to `g_type_register_static_simple&apos; window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x5b): undefined reference to `g_type_check_instance_cast&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `cvImageWidget_set_size(_GtkWidget*, int, int)&apos;: window_gtk.cpp:(.text._ZL22cvImageWidget_set_sizeP10_GtkWidgetii+0x19): undefined reference to `gtk_widget_get_type&apos; window_gtk.cpp:(.text._ZL22cvImageWidget_set_sizeP10_GtkWidgetii+0x47): undefined reference to `g_type_register_static_simple&apos;

I would be thankful for any help.

Bundling Building OpenCV as a static library gives thousands of undefined references

I am working on Ubuntu 14.04 18.04 and i want to build OpenCV(4.1.0) as static lib and create a sample program. Building OpenCV works flawlessly but i get thousands of errors when i run the test application.

Building OpenCV:

  • configure cmake:

    cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D BUILD_SHARED_LIBS=OFF -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.0/modules -D CMAKE_INSTALL_PREFIX=/usr/local/opencv ..

  • build:

    make -j8

  • install:

    sudo make install

  • pkg-config setup:

    sudo cp unix-install/opencv4.pc /usr/lib/x86_64-linux-gnu/pkgconfig/

Sample Program

#include <stdio.h>
#include <opencv2/opencv.hpp>
int main( int argc, char** argv )
{
  cv::Mat testmat;
  printf("Test\n");
  return 0;
} 
  • build:

    g++ TestApp.cpp -o TestApp `pkg-config --cflags --libs opencv4`

/usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `cvImageWidget_class_init(void*, void*)&apos;: window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0xa): undefined reference to `gtk_widget_get_type&apos; window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x15): undefined reference to `g_type_class_peek&apos; window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x20): undefined reference to `g_type_check_class_cast&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `icvOnTrackbar(_GtkWidget*, void*)&apos;: window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0xd): undefined reference to `gtk_range_get_type&apos; window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x18): undefined reference to `g_type_check_instance_cast&apos; window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x20): undefined reference to `gtk_range_get_value&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `std::_Sp_counted_ptr_inplace&lt;CvWindow, std::allocator&lt;CvWindow&gt;, (__gnu_cxx::_Lock_policy)2&gt;::_M_dispose()&apos;: window_gtk.cpp:(.text._ZNSt23_Sp_counted_ptr_inplaceI8CvWindowSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt23_Sp_counted_ptr_inplaceI8CvWindowSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x12): undefined reference to `gtk_widget_destroy&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `icvWindowThreadLoop(void*)&apos;: window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x41): undefined reference to `gtk_main_iteration_do&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x53): undefined reference to `g_usleep&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x58): undefined reference to `g_thread_yield&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x113): undefined reference to `gtk_main_iteration_do&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x11d): undefined reference to `g_usleep&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x122): undefined reference to `g_thread_yield&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `cvImageWidget_size_request(_GtkWidget*, _GtkRequisition*)&apos;: window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x19): undefined reference to `gtk_widget_get_type&apos; window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x47): undefined reference to `g_type_register_static_simple&apos; window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x5b): undefined reference to `g_type_check_instance_cast&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `cvImageWidget_set_size(_GtkWidget*, int, int)&apos;: window_gtk.cpp:(.text._ZL22cvImageWidget_set_sizeP10_GtkWidgetii+0x19): undefined reference to `gtk_widget_get_type&apos; window_gtk.cpp:(.text._ZL22cvImageWidget_set_sizeP10_GtkWidgetii+0x47): undefined reference to `g_type_register_static_simple&apos;

I would be thankful for any help.

Building OpenCV as a static library gives thousands of undefined references

I am working on Ubuntu 18.04 and i want to build OpenCV(4.1.0) as static lib and create a sample program. Building OpenCV works flawlessly but i get thousands of errors when i run the test application.

Building OpenCV:

  • configure cmake:

    cmake -D CMAKE_BUILD_TYPE=Release -D OPENCV_GENERATE_PKGCONFIG=ON -D BUILD_SHARED_LIBS=OFF -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-4.1.0/modules -D CMAKE_INSTALL_PREFIX=/usr/local/opencv ..

  • build:

    make -j8

  • install:

    sudo make install

  • pkg-config setup:

    sudo cp unix-install/opencv4.pc /usr/lib/x86_64-linux-gnu/pkgconfig/

Sample Program

#include <stdio.h>
#include <opencv2/opencv.hpp>
int main( int argc, char** argv )
{
  cv::Mat testmat;
  printf("Test\n");
  return 0;
} 
  • build:

    g++ TestApp.cpp -o TestApp `pkg-config --cflags --libs opencv4`

/usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `cvImageWidget_class_init(void*, void*)&apos;: window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0xa): undefined reference to `gtk_widget_get_type&apos; window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x15): undefined reference to `g_type_class_peek&apos; window_gtk.cpp:(.text._ZL24cvImageWidget_class_initPvS_+0x20): undefined reference to `g_type_check_class_cast&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `icvOnTrackbar(_GtkWidget*, void*)&apos;: window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0xd): undefined reference to `gtk_range_get_type&apos; window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x18): undefined reference to `g_type_check_instance_cast&apos; window_gtk.cpp:(.text._ZL13icvOnTrackbarP10_GtkWidgetPv+0x20): undefined reference to `gtk_range_get_value&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `std::_Sp_counted_ptr_inplace&lt;CvWindow, std::allocator&lt;CvWindow&gt;, (__gnu_cxx::_Lock_policy)2&gt;::_M_dispose()&apos;: window_gtk.cpp:(.text._ZNSt23_Sp_counted_ptr_inplaceI8CvWindowSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv[_ZNSt23_Sp_counted_ptr_inplaceI8CvWindowSaIS0_ELN9__gnu_cxx12_Lock_policyE2EE10_M_disposeEv]+0x12): undefined reference to `gtk_widget_destroy&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `icvWindowThreadLoop(void*)&apos;: window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x41): undefined reference to `gtk_main_iteration_do&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x53): undefined reference to `g_usleep&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x58): undefined reference to `g_thread_yield&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x113): undefined reference to `gtk_main_iteration_do&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x11d): undefined reference to `g_usleep&apos; window_gtk.cpp:(.text._ZL19icvWindowThreadLoopPv+0x122): undefined reference to `g_thread_yield&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `cvImageWidget_size_request(_GtkWidget*, _GtkRequisition*)&apos;: window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x19): undefined reference to `gtk_widget_get_type&apos; window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x47): undefined reference to `g_type_register_static_simple&apos; window_gtk.cpp:(.text._ZL26cvImageWidget_size_requestP10_GtkWidgetP15_GtkRequisition+0x5b): undefined reference to `g_type_check_instance_cast&apos; /usr/local/opencv/lib/libopencv_highgui.a(window_gtk.cpp.o): In function `cvImageWidget_set_size(_GtkWidget*, int, int)&apos;: window_gtk.cpp:(.text._ZL22cvImageWidget_set_sizeP10_GtkWidgetii+0x19): undefined reference to `gtk_widget_get_type&apos; window_gtk.cpp:(.text._ZL22cvImageWidget_set_sizeP10_GtkWidgetii+0x47): undefined reference to `g_type_register_static_simple&apos;

I would be thankful for any help.