首页 > 解决方案 > CMake 导入共享和静态库版本,但我只想要一个

问题描述

我想在项目中使用 Antlr 框架。我正在使用 CMake 来构建项目。

我想使用 Antlr 的 SHARED 库版本,而不是 STATIC 版本。它的 CMake 文件包含两者的目标。

Antlr 的 github 站点明确告诉我使用以下代码:

find_package(antlr4-runtime REQUIRED)

# add runtime include directories on this project.
include_directories( ${ANTLR4_INCLUDE_DIR} )

# add runtime to project dependencies
add_dependencies( Parsertest antlr4_shared )

# add runtime to project link libraries
target_link_libraries( Parsertest PRIVATE
                       antlr4_shared)

(另一个目标 ,antlr4_static存在,但不应使用。)

我完全像这样复制它并收到以下错误:

CMake Error at /usr/lib64/cmake/antlr4-runtime/antlr4-targets.cmake:82 (message):
  The imported target "antlr4_static" references the file

     "/usr/lib/libantlr4-runtime.a"

  but this file does not exist.

我的系统中没有安装静态库,因为我无意使用它。不过,我如何让 CMake 首先停止寻找错误的目标?我在 CMakeLists.txt 文件中没有使用它,并且对这种行为感到困惑。

标签: cmakeshared-librariesstatic-librariesantlr

解决方案


推荐阅读