由于sqlite3
的版本太旧,我安装了另一个新版本的sqlite3
。新版本安装在以下路径中:
/export/home/hh/hh/sqlite/include
/export/home/hh/hh/sqlite/lib
我改编了this FindSQLite3.cmake并在cmake
中使用它来查找新的sqlite3
。 MESSAGE
的输出显示cmake
可以找到新版本的includes
和libs
:
-- 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文件。
答案 0 :(得分:0)
在SQLITE3_LIBRARIES
(或使用cmake-gui)中设置SQLITE3_INCLUDE_DIRS
和CMakeCache.txt
,使其指向所需的库版本。删除SQLITE3_FOUND
和SQLITE3_DEFINITIONS
并重新运行CMake。