请帮帮我。我想将ICU库添加到我的项目中。我的cmake版本是2.8.12.2。
有CMakeLists.txt
cmake_minimum_required(版本2.8)
项目(TEST1)
set(CMAKE_MODULE_PATH $ {PROJECT_SOURCE_DIR}) set(CMAKE_CXX_COMPILER / usr / bin / g ++) set(CMAKE_CXX_FLAGS“$ {CMAKE_CXX_FLAGS} -D_GLIBCXX_USE_CXX11_ABI = 0 -std = c ++ 11 -Wall”)
find_package(Boost 1.54.0 COMPONENTS文件系统系统regex unit_test_framework REQUIRED) find_package(ICU 52.0 REQUIRED)
include_directories($ {} Boost_INCLUDE_DIR) link_directories($ {} Boost_LIBRARY_DIR)
add_executable(test1 src / dictionary.cpp src / main.cpp) target_link_libraries(test1 $ {Boost_LIBRARIES} pthread)
我安装了ICU库:libicu-dev,libicu-dev:i386,libicu52,libicu52:i386,libicu52-dbg:i386
但是一旦我运行CMake,我收到以下错误消息:
CMake Error at CMakeLists.txt:10 (find_package):
By not providing "FindICU.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "ICU", but
CMake did not find one.
Could not find a package configuration file provided by "ICU" (requested
version 52.1) with any of the following names:
ICUConfig.cmake
icu-config.cmake
Add the installation prefix of "ICU" to CMAKE_PREFIX_PATH or set "ICU_DIR"
to a directory containing one of the above files. If "ICU" provides a
separate development package or SDK, be sure it has been installed.
我该怎么办?请帮帮我。
通过在http://github.com/julp/FindICU.cmake的项目目录顶部添加FindICU.cmake文件解决了这个问题
它包括标题和链接库。对于小型项目,您可能只是这样做(假设您已经正确安装了ICU,并且可以手动运行)
include_directories(${ICU_INCLUDE_DIRS})
link_directories(${ICU_LIBRARY_DIRS})
add_executable(test1 src/dictionary.cpp src/main.cpp )
target_link_libraries(test1 ${ICU_LIBRARIES})
您可以在运行“cmake”时使用以下内容来打印信息,以检查cmake是否找到了正确的路径。
MESSAGE("ICU_INCLUDE_DIRS: " ${ICU_INCLUDE_DIRS})
我使用的cmake版本是3.5.2
使用CMake 3.13。
add_executable(myapp
main.cpp
)
# ICU Components Reference:
# https://cmake.org/cmake/help/latest/module/FindICU.html
# ICU components = data, i18n, io, le, lx, test, tu and uc.
find_package(ICU 61.0 COMPONENTS uc i18n REQUIRED)
# Link using the imported target names (ICU::uc, ICU::i18n, etc.)
target_link_libraries(myapp ICU::uc ICU::i18n)
注意:除非我在find_package语句中明确列出了组件,否则这不起作用。
如果需要ICU库,请使用:
find_package(ICU REQUIRED components...)
target_link_libraries(lab1 ${ICU_LIBRARIES})
如果是可选的,请使用:
find_package(ICU COMPONENTS components...)
target_link_libraries(lab1 ${ICU_LIBRARIES})
组件......是可以找到的ICU库组件列表here。 仅在add_executable命令后插入这些行!