代码cmake_minimum_required(VERSION 3.16) # 声明该项目的名称和版本号 project(MyLib VERSION 1.0) # 添加库代码文件到该库 add_library(mylib STATIC src/header.cpp) add_library(mylib_shared SHARED src/header.cpp) include_directories(include) # 指定install路径,以便于其他项目找到该库 install(TARGETS mylib mylib_shared EXPORT MyLibConfig ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin) install(FILES include/mylib.h DESTINATION include) # 生成MyLibConfig.cmake文件 include(CMakePackageConfigHelpers) write_basic_package_version_file( "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfigVersion.cmake" VERSION ${MyLib_VERSION} COMPATIBILITY AnyNewerVersion ) configure_package_config_file( "${CMAKE_CURRENT_SOURCE_DIR}/MyLibConfig.cmake.in" "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfig.cmake" INSTALL_DESTINATION cmake ) install( FILES "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfig.cmake" "${CMAKE_CURRENT_BINARY_DIR}/MyLibConfigVersion.cmake" DESTINATION cmake )在cmake时输入参数-DCMKAE_INSTALL_PREFIX=/home/czl/为什么提醒 Manually-specified variables were not used by the project: CMKAE_INSTALL_PREFIX
时间: 2024-02-12 14:04:25 浏览: 240
cmake_test cmake_test cmake_test
这个警告是因为你在命令行中手动指定了变量 `CMAKE_INSTALL_PREFIX`,但是在 CMakeLists.txt 文件中没有使用到这个变量,因此 CMake 提醒你这个变量没有被使用。
要解决这个问题,你可以在 CMakeLists.txt 文件中使用 `${CMAKE_INSTALL_PREFIX}` 变量,例如:
```
install(TARGETS mylib mylib_shared
EXPORT MyLibConfig
ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(FILES include/mylib.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
```
这样,在安装时就会使用命令行中指定的安装路径。
另外,你在命令行中拼写错误,应该是 `-DCMAKE_INSTALL_PREFIX=/home/czl/`,而不是 `-DCMKAE_INSTALL_PREFIX=/home/czl/`。
阅读全文