自莫哈韦沙漠以来,链接在自制软件中无效 [英] Linking not working in homebrew's cmake since Mojave
问题描述
我现在已经在两台计算机上重现了这种症状, cmake
似乎不再出现在 / usr / local / lib $ c中$ c>(或更恰当的说法,是将Homebrew提供的库升级为
$(brew --prefix)/ lib
),因为我将计算机升级到了macOS Mojave。
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
搜索自制字词;将结果添加到 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医生
并更新了所有自制软件包无济于事。
I've already tried brew doctor
and updated all homebrew packages to no avail.
cmake
( make
)显示为:
ld: library not found for -l<somelib>
推荐答案
我已将其隔离到以下内容更改 VERBOSE = 1 make
日志...
I've isolated this to the following change in the VERBOSE=1 make
logs...
- 高塞拉利昂(< ; = 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< dir>
此选项类似于-sysroot
选项,但仅适用于头文件(达尔文目标除外,它适用于可以同时访问头文件和库)。有关更多信息,请参见-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
会这样做?我的想法是要解决 / 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.
这篇关于自莫哈韦沙漠以来,链接在自制软件中无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!