0

When I compile my code that uses OpenCV and caffe, I get the following linker errors:

../libs/libopencv_highgui.so: undefined reference to `g_mutex_lock'
../libs/libgstbase-0.10.so.0: undefined reference to `g_cond_init'
../libs/libopencv_highgui.so: undefined reference to `g_mutex_unlock'
../libs/libopencv_highgui.so: undefined reference to `g_cond_broadcast'
../libs/libgstreamer-0.10.so.0: undefined reference to `g_cond_wait_until'
../libs/libopencv_highgui.so: undefined reference to `g_mutex_new'
...
collect2: ld returned 1 exit status

This my g+ commmand:

 g++ -DCPU_ONLY=1 test.cpp -o test -I../include -I../include/openblas -L../libs 
 -Wl,-rpath=../libs -lcaffe -lglog -lboost_system -lopencv_core -lopencv_highgui 
 -lopencv_imgproc

What am I missing?

Cœur
  • 37,241
  • 25
  • 195
  • 267
tidy
  • 4,747
  • 9
  • 49
  • 89

1 Answers1

1

Yep, this is a simple case of not linking against glib.

In general, to fix this kind of thing, google one of the symbol names(g_mutex_lock, for example) to figure out what library it comes from. In this case, it is glib. Then, look in their documentation for help compiling applications that use their library(if you can't figure it out on your own). In this case, you end up here.

Once you have made sure you have all required packages installed, you augment your compiler options as needed.

In your case, try g++ -DCPU_ONLY=1 test.cpp -o test `pkg-config --cflags glib-2.0` -I../include -I../include/openblas `pkconfig --libs glib-2.0` -L../libs -Wl,-rpath=../libs -lcaffe -lglog -lboost_system -lopencv_core -lopencv_highgui -lopencv_imgproc

Note the use of pkg-config. For reference, compiling a sample application that uses only glib might look like this: gcc hello.c `pkg-config --cflags --libs glib-2.0`

rationalcoder
  • 1,587
  • 1
  • 15
  • 29