我有以下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.
我还尝试了this和this作为替代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 include目录和库的位置,因此可以直接将路径设置为这些路径,因此在
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)
沿着这两个方向的工作应该可行。
就个人而言,我建议第一种方法。
关于c++ - 如何在没有外部脚本的情况下链接CMake和SQLite?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41640029/