Guide install mysql connector for c++ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 sudo apt-get -y install mysql-servermysql -uroot -pxxxxxx sudo apt-get -y install libboost-all-devsudo apt-cache search libmysqlcppconn sudo apt-get -y install libmysqlcppconn-devsudo apt-get install libmysqlcppconn7v5
link in CMakeLists.txt target link with options mysqlcppconn
eg.
1 2 3 4 5 6 target_link_libraries (Backend Config Util Model mysqlcppconn )
mysqlcppconn-config.cmake 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 include(FindPackageHandleStandardArgs) set (MYSQLCPPCONN_ROOT_DIR "" CACHE PATH "Folder contains mysqlcppconn" )if (WIN32) find_path(MYSQLCPPCONN_INCLUDE_DIR cppconn/driver.h PATHS ${MYSQLCPPCONN_ROOT_DIR} ) else () find_path(MYSQLCPPCONN_INCLUDE_DIR cppconn/dirver.h PATHS ${MYSQLCPPCONN_ROOT_DIR} ) endif() if (MSVC) find_library(MYSQLCPPCONN_LIBRARY_RELEASE mysqlcppconn PATHS ${MYSQLCPPCONN_ROOT_DIR} PATH_SUFFIXES Release) find_library(MYSQLCPPCONN_LIBRARY_DEBUG mysqlcppconn PATHS ${MYSQLCPPCONN_ROOT_DIR} PATH_SUFFIXES Debug) set (MYSQLCPPCONN_LIBRARY optimized ${MYSQLCPPCONN_LIBRARY_RELEASE} debug ${MYSQLCPPCONN_LIBRARY_DEBUG} ) else () find_library(MYSQLCPPCONN_LIBRARY mysqlcppconn PATHS ${MYSQLCPPCONN_ROOT_DIR} PATH_SUFFIXES lib lib64) endif() find_package_handle_standard_args(MYSQLCPPCONN DEFAULT_MSG MYSQLCPPCONN_INCLUDE_DIR MYSQLCPPCONN_LIBRARY) if (MYSQLCPPCONN_FOUND) set (MYSQLCPPCONN_INCLUDE_DIRS ${MYSQLCPPCONN_INCLUDE_DIR} ) set (MYSQLCPPCONN_LIBRARIES ${MYSQLCPPCONN_LIBRARY} ) message(STATUS "Found mysqlcppconn (include: ${MYSQLCPPCONN_INCLUDE_DIR} , library: ${MYSQLCPPCONN_LIBRARY} )" ) mark_as_advanced(MYSQLCPPCONN_ROOT_DIR MYSQLCPPCONN_LIBRARY_RELEASE MYSQLCPPCONN_LIBRARY_DEBUG MYSQLCPPCONN_LIBRARY MYSQLCPPCONN_INCLUDE_DIR) endif()
CMakeLists.txt
for find_package(MYSQLCPPCONN REQUIRED)
we copy user-defined mysqlcppconn-config.cmake
to /usr/lib/cmake/mysqlcppconn
1 2 3 4 find_package(MYSQLCPPCONN REQUIRED) include_directories(${MYSQLCPPCONN_INCLUDE_DIRS} ) target_link_libraries (demo ${MYSQLCPPCONN_LIBRARIES} )
Reference
History
2180118: created.
20180223: add mysqlcppconn-config.cmake.