Version of Virtual machine: redhat7.0 64bit
Version of database: MySQL5.7
1, the extracted files in the corresponding library, the head file copy to the system can find the location
For example: I then installed the database files are in:/usr/local/
Execution: cp/usr/local/include/*/usr/include/
Note that when copying, if the * contains folders, you need to use:
Cp-r/usr/local/include/*/usr/include/
(CP will recursively replicate all subdirectories and files in that directory)
Feel free to write a test file: 1.cpp
# include <iostream>
# include <mysql/mysql.h>
using namespace Std;
int main ()
{
MYSQL * Connection;
Connection = Mysql_init (NULL);
return 0;
}
Then compile the file with g++-o 1 1.cpp-lmysqlcient
Unfortunately, it was also expected that a problem arose:
650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/89/43/wKioL1gOA-nRQRJWAAAd1p3jhe8107.png-wh_500x0-wm_3 -wmp_4-s_1009283184.png "title=" Qq20161024204810.png "alt=" Wkiol1goa-nrqrjwaaad1p3jhe8107.png-wh_50 "/>
The library file could not be found.
Terminal input command: Mysql_config--libs
650) this.width=650; "Src=" Http://s3.51cto.com/wyfs02/M01/89/45/wKiom1gOBYTACaqoAAAX3czMFw0193.png-wh_500x0-wm_3 -wmp_4-s_3707091375.png "title=" Qq20161024204935.png "alt=" Wkiom1gobytacaqoaaax3czmfw0193.png-wh_50 "/>
Now we compile with the path, execute: g++-l/usr/local/lib/mysql-lmysqlclient-o 1 1.cpp
Compiled by.
Link when the default path is/usr/local/lib, a layer of directories, we will copy the MySQL files under the Lib
Execution: cp/usr/local/lib/mysql/*/usr/local/lib/
In this case, delete the MySQL folder under Lib is not a hindrance.
Perform g++-o 1 1.cpp-lmysqlclient compilation again. 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0058.gif "alt=" J_0058.gif "/>
This article is from the "11561636" blog, please be sure to keep this source http://11571636.blog.51cto.com/11561636/1865184
Linux under c++/c connection MySQL database