Reputation: 927
I get a strange linker error when building a project (which uses GStreamer 1.0 and therefore depends on Glib 2.0) with cmake and linking against glib library. Glib is installed using macports, libglib-2.0.0.dylib is present in /opt/local/lib/. FindGLIB successfully finds its header files (compiling works) and also ${GLIB_LIBRARIES} provides the right path to the library.
The error message is
[100%] Linking CXX executable ../bin/presenter
Undefined symbols for architecture x86_64:
"_g_object_set", referenced from:
...
"_g_type_check_instance_cast", referenced from:
...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
If I remove glib from the list completely it's also copmplaining about missing reference to g_print and g_printerr. Is it possible that the linking is done correctly but the functions are just missing for some reason inside the library?
How can I fix it?
Upvotes: 2
Views: 522
Reputation: 927
Finally found my mistake. When using FindGLIB of the Webkit project, it by default searches only for the main glib library. It's components have to be passed in addition to be found:
find_package(GLIB COMPONENTS gobject REQUIRED)
would find glib itself and save it in ${GLIB_LIBRARIES}
and also gobject and save it in ${GLIB_GOBJECT_LIBRARIES}
so they can be used in target_link_libraries()
Reminder: Always read the comments in the file headers - they often contain useful information...
# Optionally, the COMPONENTS keyword can be passed to find_package()
# and Glib components can be looked for. Currently, the following
# components can be used, and they define the following variables if
# found:
#
# gio: GLIB_GIO_LIBRARIES
# gobject: GLIB_GOBJECT_LIBRARIES
# gmodule: GLIB_GMODULE_LIBRARIES
# gthread: GLIB_GTHREAD_LIBRARIES
Upvotes: 2