macos - MacPorts 中的 glib 的 g_object_set 链接器错误

标签 macos cmake macports glib

使用 cmake 构建项目(使用 GStreamer 1.0,因此依赖于 Glib 2.0)并链接 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 的引用。是否有可能链接已正确完成,但由于某种原因在库内缺少函数?

如何修复它?

最佳答案

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

find_package(GLIB COMPONENTS gobject REQUIRED)

会找到glib本身并将其保存在${GLIB_LIBRARIES}中,也会找到gobject并将其保存在${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

关于macos - MacPorts 中的 glib 的 g_object_set 链接器错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33281019/

相关文章:

macos - postgres 抛出错误 psql : FATAL: role "username" does not exist

cmake - 如何判断 CMake 是否使用了选项的初始值?

python - 使用 mac 端口安装 opencv 时启用 python 支持

macos - Mac OS X 服务 : enable without user interaction?

xcode - 在配置设置中使用 .xcconfig 文件的路径

python - 错误 : command 'clang' failed with exit status 1 : On installing pandas on MacOS Big Sur M1

CMake:如何拥有复制文件的目标

java - 配置 CMake C++/Java 项目以与 Eclipse 配合使用

bash - 如何强制 OpenSSL 使用旧密码

macports - 查看通过 MacPorts 安装的内容