来自MacPorts的glib的g_object_set链接器错误

时间:2015-10-22 12:26:21

标签: macos cmake macports glib

在构建项目(使用GStreamer 1.0,因此依赖于Glib 2.0)时使用cmake并链接到glib库时出现奇怪的链接器错误。 Glib使用macports安装,libglib-2.0.0.dylib存在于/ opt / local / lib /中。 FindGLIB成功找到其头文件(编译工作),$ {GLIB_LIBRARIES}提供了库的正确路径。

错误消息是

[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)

如果我从列表中完全删除了glib,那么它也会对缺少对g_print和g_printerr的引用进行讨论。链接是否可能正确完成但是函数在库中由于某种原因而丢失了?

我该如何解决?

1 个答案:

答案 0 :(得分:2)

终于找到了我的错误。使用Webkit项目的FindGLIB时,它默认只搜索主glib库。除了找到它之外,还必须传递它的组件:

find_package(GLIB COMPONENTS gobject REQUIRED)

会找到glib本身并将其保存在${GLIB_LIBRARIES}中,然后将其保存并保存在${GLIB_GOBJECT_LIBRARIES}中,以便它们可以在target_link_libraries()中使用

提醒:始终阅读文件标题中的注释 - 它们通常包含有用的信息......

# 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