【问题标题】:error message in adding sqlite3 library in my project在我的项目中添加 sqlite3 库时出现错误消息
【发布时间】:2016-07-12 14:11:45
【问题描述】:

我有一个 C++ 项目,我想在上面使用 sqlite3。我正在使用 CMake 构建并向 CMakeLists.txt 添加一些行,这里是:

project(Test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set(CMAKE_BUILD_TYPE Debug)
cmake_minimum_required(VERSION 2.8)
aux_source_directory(. SRC_LIST)
add_executable(${PROJECT_NAME} ${SRC_LIST})
set(CMAKE_CXX_FLAGS_DEBUG  "-g")

find_path(SQLITE3_INCLUDE_DIR sqlite3.h)
find_library(SQLITE3_LIBRARY sqlite3)
if(NOT SQLITE3_INCLUDE_DIR)
  message(SEND_ERROR "Failed to find sqlite3")
endif()
if(NOT SQLITE3_LIBRARY)
  message(SEND_ERROR "Failed to find the sqlite3 library")
endif()

当我想朗姆酒 cmake 命令时,它会得到我Failed to find sqlite3Failed to find the sqlite3 library 并且可以找到它。

我正在使用 ubuntu+qtcreator 和我安装的 sqlite3 版本:

> sqlite3 --version
3.8.2 2013-12-06 14:53:30 27392018af4c38cc203a04b8013e2afdb1cebd0d

谢谢大家...!

【问题讨论】:

  • SQLite 是可嵌入的。为什么不能包含源代码?
  • 您是否安装了libsqlite3-dev
  • @Igor 我在我的源代码中包含了 sqlite3.h!是不足够的?还是必须包含其他内容??
  • @Mehdi,是的,你还需要 sqlite3.c 文件。
  • @mehdi 您还需要将代码与 libsqlite3 库链接。 target_link_library(${PROJECT_NAME} ${SQLITE3_LIBRARY})

标签: c++ linux sqlite cmake


【解决方案1】:

她的一个最有效的例子,即我已经删除了不相关的东西 cmake...

include_directories(${CMAKE_CURRENT_SOURCE_DIR}/sqlite3/)
set(sqlite3_srcs 
  ${CMAKE_CURRENT_SOURCE_DIR}/sqlite3/sqlite3.c
  ${CMAKE_CURRENT_SOURCE_DIR}/sqlite3/sqlite3.h 
)
....
add_library(mylib SHARED
  ${sqlite3_srcs} 
)
target_link_libraries(foooo  mylib)

【讨论】:

    猜你喜欢
    • 2019-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-29
    • 1970-01-01
    相关资源
    最近更新 更多