当前位置:  开发笔记 > 编程语言 > 正文

如何在没有外部脚本的情况下链接CMake和SQLite?

如何解决《如何在没有外部脚本的情况下链接CMake和SQLite?》经验,为你挑选了1个好方法。

我有以下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> fedepad..:

你基本上有两个选择:
1)FindSQLite3.cmakecmake项目的根目录中调用一个目录,就像 你已经尝试过的下面的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)

这两个方向的东西应该有效.
就个人而言,我建议采用第一种方法.


如果您使用链接的FindSQLite3.cmake,请更改FIND_LIBRARY,如下所示,其他人将找不到libsqlite3:`#查找库.FIND_LIBRARY(SQLITE3_LIBRARY NAMES sqlite3)`
推荐阅读
臭小子
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有