首页 > 代码库 > rhel7 编写CMakeList.txt编译运行MySQL官方例子代码
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)#---includeSET(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官方例子代码
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。