我有以下CMakeLists:
cmake_minimum_required (VERSION 2.8.12.2) project (Tutorial) find_package (sqlite3) if (SQLITE3_FOUND) include_directories(${SQLITE3_INCLUDE_DIRS}) target_link_libraries (new ${SQLITE3_LIBRARIES}) endif (SQLITE3_FOUND) add_executable(Tutorial new.cpp)
但是,当我cmake时,我收到以下消息:
CMake Warning at CMakeLists.txt:3 (find_package): By not providing "Findsqlite3.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "sqlite3", but CMake did not find one. Could not find a package configuration file provided by "sqlite3" with any of the following names: sqlite3Config.cmake sqlite3-config.cmake Add the installation prefix of "sqlite3" to CMAKE_PREFIX_PATH or set "sqlite3_DIR" to a directory containing one of the above files. If "sqlite3" provides a separate development package or SDK, be sure it has been installed.
我自己也尝试这个和这个替代CMakeLists文件,但这些都没有工作.
我也尝试过这个并没有用:
FIND_PATH(SQLITE3_INCLUDE_DIR NAMES sqlite3.h) FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite) INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(SQLITE3 DEFAULT_MSG SQLITE3_LIBRARY SQLITE3_INCLUDE_DIR) IF(SQLITE3_FOUND) SET(SQLITE3_LIBRARIES ${SQLITE3_LIBRARY}) SET(SQLITE3_INCLUDE_DIRS ${SQLITE3_INCLUDE_DIR}) ELSE(SQLITE3_FOUND) SET(SQLITE3_LIBRARIES) SET(SQLITE3_INCLUDE_DIRS) ENDIF(SQLITE3_FOUND) MARK_AS_ADVANCED(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES)
如何在不使用扩展名的情况下链接SQLite?
谢谢!
你基本上有两个选择:
1)FindSQLite3.cmake
在cmake
项目的根目录中调用一个目录,就像
你已经尝试过的下面的FindSQLite3.cmake但你需要有类似下面这样的东西
cmake_minimum_required (VERSION 2.8.12.2) project (Tutorial) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake") add_executable(tutorial new.cpp) find_package (SQLite3) if (SQLITE3_FOUND) include_directories(${SQLITE3_INCLUDE_DIRS}) target_link_libraries (tutorial ${SQLITE3_LIBRARIES}) endif (SQLITE3_FOUND)
2),因为你知道你的sqlite3的位置包括目录和库,你可以直接设置路径的,在你的CMakeLists.txt
你将有类似link_directories()
并且include_directories()
,例如,你将有以下几行:
cmake_minimum_required (VERSION 2.8.12.2) project (Tutorial) add_executable(tutorial new.cpp) include_directories(/usr/include) link_directories(/usr/lib) target_link_libraries(tutorial sqlite3)
这两个方向的东西应该有效.
就个人而言,我建议采用第一种方法.