自 Mojave 以来,链接在自制软件的 cmake 中不起作用 [英] Linking not working in homebrew's cmake since Mojave

查看:13
本文介绍了自 Mojave 以来,链接在自制软件的 cmake 中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在已经在两台计算机上重现了这个症状,cmake 似乎不再查看 /usr/local/lib(或者更准确地说,$(brew --prefix)/lib) 用于自将我的机器升级到 macOS Mojave 以来 Homebrew 提供的库.

I've reproduced this symptom on two computers now, cmake seems to no longer look in /usr/local/lib (or more properly, $(brew --prefix)/lib) for Homebrew-provided libraries since upgrading my machine to macOS Mojave.

尽管有一些方法可以绕过这个(例如,使用 EXECUTE_PROCESS 搜索 homebrew 前缀;将结果添加到 LINK_LIBRARIES(...) 命令)没有一个是理想的.Mojave 发生了什么改变来打破这种行为?

Although there are ways to circumvent this (e.g. search for homebrew prefix using EXECUTE_PROCESS; add the result to LINK_LIBRARIES(...) command) none are ideal. What changed in Mojave to break this behavior?

临时解决方法是将以下内容添加到 CMakeLists.txt:

The temporary workaround is to add the following to CMakeLists.txt:

# WARNING: Don't hard-code this path
LINK_DIRECTORIES(/usr/local/lib)

我已经尝试过 brew doctor 并更新了所有自制软件包但无济于事.

I've already tried brew doctor and updated all homebrew packages to no avail.

cmake (make) 显示的具体错误是:

The specific error that cmake (make) shows is:

ld: library not found for -l<somelib>

我在 Homebrew 论坛上问过这个问题Apple 开发者论坛.

I've asked the question on the Homebrew forums and the Apple developer forums.

推荐答案

我已将此与 VERBOSE=1 make 日志中的以下更改隔离...

I've isolated this to the following change in the VERBOSE=1 make logs...

  • High Sierra (<=10.13) 及以下版本使用 -isysroot 命令.
  • Mojave (>=10.14) 确实使用 -isysroot 命令.
  • High Sierra (<=10.13) and below did NOT use the -isysroot command.
  • Mojave (>=10.14) DOES use the -isysroot command.

来自 gnu.org:

-isysroot

此选项类似于 --sysroot 选项,但仅适用于头文件(除了 Darwin 目标,它同时适用于头文件和库).有关详细信息,请参阅 --sysroot 选项.

-isysroot <dir> This option is like the --sysroot option, but applies only to header files (except for Darwin targets, where it applies to both header files and libraries). See the --sysroot option for more information.

因此,此标志仅在 Apple 上专门破坏了 lib 搜索路径.这导致编译永远不会在标准 ld 位置查找,这可以通过键入 ld -v dummy 来查看.

So this flag specifically clobbers the lib search path only on Apple. This results in the compilation never looking in the standard ld locations, which can be seen by typing ld -v dummy.

Library search paths:
    /usr/lib
    /usr/local/lib

cmake 为什么要这样做?我的想法是修复新 Mojave SDK 引入的 /usr/local/include 问题行为.

Why does cmake do this? My thought is it was to fix the /usr/local/include issues introduced with the new Mojave SDK behavior.

不幸的是,我找不到 cmake 编译标志来添加默认库搜索路径.现在我找到的唯一解决方案是将以下内容添加到我的项目中:

Unfortunately, I can't find a cmake compile flag to add the default library search paths back in. For now the only solution I've found is to add the following to my project:

IF(APPLE)
    # Fix linking on 10.14+. See https://stackoverflow.com/questions/54068035
    LINK_DIRECTORIES(/usr/local/lib)
ENDIF()

我不确定这是否是需要上游 cmake 补丁的行为.如果有更好的解决方案,请提供.

I'm not sure if this is a behavior that warrants an upstream cmake patch. If there is a better solution, please provide it.

这篇关于自 Mojave 以来,链接在自制软件的 cmake 中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆