Note: If you need to install MySQL on RHEL7, click here
1. The following MySQL link library version is used for boost (please download the latest link library and documentation and example of C + + connection database operation if required)
Red Hat Enterprise linux 7/oracle Linux 7 (x86, 64-bit), compressed TAR Archive
2. Download boost (please download the latest version if necessary)
Boost_1_64_0.tar.gz
3.cmakelist.txt (not good at beginner's writing)
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: Copylib*.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 write CMakeList.txt compile run MySQL official example code