'sqlite3_prepare_v2'未在此范围内声明

时间:2016-03-30 04:10:03

标签: sqlite cmake

由于sqlite3的版本太旧,我安装了另一个新版本的sqlite3。新版本安装在以下路径中:

/export/home/hh/hh/sqlite/include
/export/home/hh/hh/sqlite/lib

我改编了this FindSQLite3.cmake并在cmake中使用它来查找新的sqlite3MESSAGE的输出显示cmake可以找到新版本的includeslibs

-- SQLite3 include: /export/home/hh/hh/sqlite/include
-- SQLite3 lib: /export/home/hh/hh/sqlite/lib/libsqlite3.so
-- SQLite3 IS USED

安装项目时,出现错误‘sqlite3_prepare_v2’ was not declared in this scope。但是sqlite3_prepare_v2包含在新版本中,应该声明它。我认为可能的原因是cmake无法找到新版本而是找到旧版本。有帮助吗?提前谢谢!

我的FindSQLite3.cmake

if (SQLITE3_LIBRARIES AND SQLITE3_INCLUDE_DIRS)
  # in cache already
  set(SQLITE3_FOUND TRUE)
else (SQLITE3_LIBRARIES AND SQLITE3_INCLUDE_DIRS)
  # use pkg-config to get the directories and then use these values
  # in the FIND_PATH() and FIND_LIBRARY() calls
  if (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
    include(UsePkgConfig)
    pkgconfig(sqlite3 _SQLITE3_INCLUDEDIR _SQLITE3_LIBDIR _SQLITE3_LDFLAGS _SQLITE3_CFLAGS)
    MESSAGE(STATUS "Test ${_SQLITE3_INCLUDEDIR} ${_SQLITE3_LIBDIR} ${_SQLITE3_LDFLAGS} ${_SQLITE3_CFLAGS}")
  else (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)
    find_package(PkgConfig REQUIRED)
    #MESSAGE(STATUS "TEST-1")
    if (PKG_CONFIG_FOUND)
      pkg_check_modules(_SQLITE3 REQUIRED sqlite-3.11)
    #MESSAGE(STATUS "TEST-2")
    endif (PKG_CONFIG_FOUND)
  endif (${CMAKE_MAJOR_VERSION} EQUAL 2 AND ${CMAKE_MINOR_VERSION} EQUAL 6)

   find_path(SQLITE3_INCLUDE_DIR
    NAMES
      sqlite3.h
    PATHS
      ${_SQLITE3_INCLUDEDIR}
      /export/home/hh/hh/sqlite/include
  )

  find_library(SQLITE3_LIBRARY
    NAMES
      sqlite3
    PATHS
      ${_SQLITE3_LIBDIR}
      /export/home/hh/hh/sqlite/lib
  )

  if (SQLITE3_LIBRARY)
    set(SQLITE3_FOUND TRUE)
  endif (SQLITE3_LIBRARY)

  set(SQLITE3_INCLUDE_DIRS
    ${SQLITE3_INCLUDE_DIR}  
  )

#MESSAGE(STATUS "${SQLITE3_INCLUDE_DIR}")

  if (SQLITE3_FOUND)
    set(SQLITE3_LIBRARIES
      ${SQLITE3_LIBRARIES}
      ${SQLITE3_LIBRARY}
    )
#MESSAGE(STATUS "${SQLITE3_LIBRARIES} ${SQLITE3_LIBRARY}")
  endif (SQLITE3_FOUND)

  if (SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES)
     set(SQLITE3_FOUND TRUE)
  endif (SQLITE3_INCLUDE_DIRS AND SQLITE3_LIBRARIES)

  if (SQLITE3_FOUND)
    if (NOT Sqlite3_FIND_QUIETLY)
#      MESSAGE(STATUS "Found Sqlite3: ${SQLITE3_LIBRARIES}")
    endif (NOT Sqlite3_FIND_QUIETLY)
  else (SQLITE3_FOUND)
    if (Sqlite3_FIND_REQUIRED)
      MESSAGE(FATAL_ERROR "Could not find Sqlite3")
    endif (Sqlite3_FIND_REQUIRED)
  endif (SQLITE3_FOUND)

  # show the SQLITE3_INCLUDE_DIRS and SQLITE3_LIBRARIES variables only in the advanced view
  mark_as_advanced(SQLITE3_INCLUDE_DIRS SQLITE3_LIBRARIES)

endif (SQLITE3_LIBRARIES AND SQLITE3_INCLUDE_DIRS)

我的CMakeLists.txt中的代码行:

LIST(APPEND CMAKE_INCLUDE_PATH "/export/home/hh/hh/sqlite/include")
LIST(APPEND CMAKE_LIBRARY_PATH "/export/home/hh/hh/sqlite/lib")

LIST(APPEND CMAKE_MODULE_PATH "/export/home/hh/hh/iRoot-make/cmake")

FIND_PACKAGE(SQLite3 REQUIRED)

MESSAGE(STATUS "SQLite3 include: ${SQLITE3_INCLUDE_DIRS}")
MESSAGE(STATUS "SQLite3 lib: ${SQLITE3_LIBRARIES}")

IF(SQLITE3_FOUND)
    MESSAGE(STATUS "SQLite3 IS USED")
    INCLUDE_DIRECTORIES(${SQLITE_INCLUDE_DIRS})
    LINK_DIRECTORIES(${SQLITE3_LIBRARIES})
ELSE(SQLITE3_FOUND)
    MESSAGE(STATUS "SQLite3 IS NOT FOUND")
ENDIF(SQLITE3_FOUND)

aux_source_directory(. DIR_SRCS)
ADD_EXECUTABLE(test ${DIR_SRCS})

#TARGET_LINK_LIBRARIES(test ${SQLITE3_LIBRARIES} ${Boost_LIBRARIES} ${MPI_LIBRARIES} ${VTK_LIBRARIES})

# set location of binary generated by the program, 
# here PROJECT_BINARY_DIR = DIR OF build
SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)

# set location of lib generated by the program
SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)

install(TARGETS test DESTINATION bin)

sqlite3.h包含在我的标题中:

#include "sqlite3.h"

sqlite3_prepare_v2用于相应的cpp文件。

1 个答案:

答案 0 :(得分:0)

SQLITE3_LIBRARIES(或使用cmake-gui)中设置SQLITE3_INCLUDE_DIRSCMakeCache.txt,使其指向所需的库版本。删除SQLITE3_FOUNDSQLITE3_DEFINITIONS并重新运行CMake。