我正在运行macOS 10.14,并安装了bison
的{{1}} 3.2版,但它拒绝链接:
brew
我的$ brew link bison --force
Warning: Refusing to link macOS-provided software: bison
If you need to have bison first in your PATH run:
echo 'export PATH="/usr/local/opt/bison/bin:$PATH"' >> ~/.bash_profile
For compilers to find bison you may need to set:
export LDFLAGS="-L/usr/local/opt/bison/lib"
有以下几行:
CMakeLists.txt
find_package(BISON 3.2 REQUIRED)
...
message(STATUS "Found bison ${BISON_VERSION} at: ${BISON_EXECUTABLE}")
失败,显示以下输出:
cmake
系统安装的Could NOT find BISON: Found unsuitable version "2.3", but required is at
least "3.2" (found /usr/bin/bison)
的版本为2.3,并且我知道Homebrew安装的版本为3.2。
bison
模块显然使用了FindBISON
CMake指令,并且我尝试将find_program
添加到/usr/local/opt/bison/bin
,但是总是首先选择CMAKE_PROGRAM_PATH
否有什么关系。如何强制CMake支持Bison可执行文件的Homebrew安装版本?
答案 0 :(得分:1)
由于macos系统中的某些内容取决于flex和bison的默认版本,因此它们安装在用户常规$PATH
之外。解决方案是确保您(和您的用户)将程序的brew前缀添加到他们的路径(可以通过运行brew --prefix bison
等找到)。解决此问题时,请务必清除CMake缓存,因为BISON_EXECUTABLE
(等)已被缓存。
另一个“自动”选项是将此逻辑放入您的CMake文件中。几个开源项目就这样解决了。我可以找到的最早的修复程序示例来自this commit to STP(下面复制了基本部分)。
# On macOS, search Homebrew for keg-only versions of Bison and Flex. Xcode does
# not provide new enough versions for us to use.
if (CMAKE_HOST_SYSTEM_NAME MATCHES "Darwin")
execute_process(
COMMAND brew --prefix bison
RESULT_VARIABLE BREW_BISON
OUTPUT_VARIABLE BREW_BISON_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_BISON EQUAL 0 AND EXISTS "${BREW_BISON_PREFIX}")
message(STATUS "Found Bison keg installed by Homebrew at ${BREW_BISON_PREFIX}")
set(BISON_EXECUTABLE "${BREW_BISON_PREFIX}/bin/bison")
endif()
execute_process(
COMMAND brew --prefix flex
RESULT_VARIABLE BREW_FLEX
OUTPUT_VARIABLE BREW_FLEX_PREFIX
OUTPUT_STRIP_TRAILING_WHITESPACE
)
if (BREW_FLEX EQUAL 0 AND EXISTS "${BREW_FLEX_PREFIX}")
message(STATUS "Found Flex keg installed by Homebrew at ${BREW_FLEX_PREFIX}")
set(FLEX_EXECUTABLE "${BREW_FLEX_PREFIX}/bin/flex")
endif()
endif()
find_package(bison REQUIRED)
find_package(flex REQUIRED)