如何在没有外部脚本的情况下链接CMake和SQLite? [英] How can I link CMake and SQLite without an external script?

查看:137
本文介绍了如何在没有外部脚本的情况下链接CMake和SQLite?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下CMakeLists:

I have the following 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)

但是,当我执行命令时,会收到以下消息:

However, when I cmake, I get the following message:

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.

我也尝试过.

我也试过了,但是没用:

I also tried this and it didn't work:

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?

How can I link SQLite without using an extension?

谢谢!

推荐答案

您基本上有两种选择:
1)在项目的根目录下的名为 cmake 的目录中有一个 FindSQLite3.cmake ,例如以下

You have basically two options:
1) have a FindSQLite3.cmake in a directory called cmake inside your project's root directory like the following FindSQLite3.cmake that you already tried but you need to have something like the following

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(),例如您将有以下几行:

2) since you know the location of your sqlite3 include directory and library you could directly set the path to those, in your CMakeLists.txt you will have something like link_directories() and include_directories(), e.g. you will have the following lines:

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)

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

Something along those two directions should work.
Personally, I would suggest the first approach.

这篇关于如何在没有外部脚本的情况下链接CMake和SQLite?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆