rhel7 编写CMakeList.txt编译运行MySQL官方例子代码

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了rhel7 编写CMakeList.txt编译运行MySQL官方例子代码相关的知识,希望对你有一定的参考价值。

注:若需要参考rhel7上安装mysql点击此处

1.下面MySQL链接库版本用到了boost(若需要请到官网下载最新链接库文档和C++连接数据库操作示例)

 Red Hat Enterprise Linux 7 / Oracle Linux 7 (x86, 64-bit), Compressed TAR Archive

2.下载boost(若需要请到官网下载最新版本)

 boost_1_64_0.tar.gz

3.CMakeList.txt(初学写的不好)

cmake_minimum_required(VERSION 2.6)
PROJECT(tools)

#MESSAGE(SEND_ERROR "Send Error." "${CMAKE_CURRENT_SOURCE_DIR}") 
#MESSAGE(STATUS "Status." "${PROJECT_SOURCE_DIR}") 
#MESSAGE(FATAL_ERROR "Fatal Error." "${PROJECT_BINARY_DIR}")

#ADD_SUBDIRECTORY(SRC_SUBDIR_LIST)
#SET(SRC_LIST ${SRC_LIST} main.cpp)
AUX_SOURCE_DIRECTORY(. SRC_LIST)
SET(EXECUTABLE ${SRC_LIST})
SET(TARGET_NAME mysqltransfer)


#---include
SET(INCLUDE_LIST ${INCLUDE_LIST} ${CMAKE_CURRENT_LIST_DIR}/../include/)
INCLUDE_DIRECTORIES(${INCLUDE_LIST})


#SET(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/../lib/)
#ADD_LIBRARY(${LINK_NAME} SHARED ${LINKABLE})
SET(EXECUTABLE_OUTPUT_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../bin/)
ADD_EXECUTABLE(${TARGET_NAME} ${EXECUTABLE})


#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMYSQLCLIENT_STATIC_LINKING=1")
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Bdynamic")

#---dynamically steps---
#---step 1:copy lib*.so.7.1.1.9 /usr/local/libX
#---step 2:ln -s lib*.so.7.1.1.9 lib*.so.7
#---step 3:ln -s lib*.so.7 lib*.so

#---dynamic1-mysqlcppconn---
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -lmysqlcppconn")
LINK_DIRECTORIES(${CMAKE_CURRENT_LIST_DIR}/../lib/)

#---dynamic2-mysqlcppconn---
#TARGET_LINK_LIBRARIES(${TARGET_NAME} mysqlcppconn)

#---dynamic3-mysqlcppconn---
#FIND_LIBRARY(MySQL_CppConn NAMES mysqlcppconn PATHS ${PROJECT_SOURCE_DIR}/../lib/)
#IF(MySQL_CppConn)
#    SET(LIBS_LIST ${LIBS_LIST} mysqlcppconn)
#    TARGET_LINK_LIBRARIES(${TARGET_NAME} ${LIBS_LIST})
#ELSE(MySQL_CppConn)
#    MESSAGE(SEND_ERROR "\\tmysqlcppconn not found!\\n")
#ENDIF(MySQL_CppConn)

#---static-mysqlcppconn---
#SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ldl")
#ADD_LIBRARY(mysqlcppconn STATIC IMPORTED)
#SET_PROPERTY(TARGET mysqlcppconn PROPERTY IMPORTED_LOCATION ${PROJECT_SOURCE_DIR}/../lib/libmysqlcppconn-static.a)
#TARGET_LINK_LIBRARIES(${TARGET_NAME} mysqlcppconn pthread)


#SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES -DBOOST_ROOT boost)
SET(BOOST_ROOT "/usr/local/boost")
#SET(BOOST_INCLUDEDIR "/usr/local/boost/include")
#SET(BOOST_LIBRARYDIR "/usr/local/boost/libs")
FIND_PACKAGE(Boost)
IF(Boost_FOUND)
    #TARGET_INCLUDE_DIRECTORIES(${TARGET_NAME} INTERFACE ${Boost_INCLUDE_DIRS})
    INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
    #LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
    TARGET_LINK_LIBRARIES(${TARGET_NAME} ${Boost_LIBRARIES})
ELSE(Boost_FOUND)
    MESSAGE(SEND_ERROR "\\tboost not found!\\n")
ENDIF(Boost_FOUND)


#MESSAGE(STATUS "Test Messages:\\n\\t" ${PROJECT_SOURCE_DIR}/../lib/)

 

以上是关于rhel7 编写CMakeList.txt编译运行MySQL官方例子代码的主要内容,如果未能解决你的问题,请参考以下文章

怎样编写Cmake的配置文件Cmakelist.txt

CMakeList.txt------- 一个cmake实例

单个源文件下CmakeList.txt

cartographer之CMakeList.txt

在 cmakelist.txt 中添加和链接 mysql 库

在 cmakelist.txt 中添加和链接 mysql 库