Reputation: 11
I have the following compile time error I cannot find the reason of: fatal error: mysql_connection.h: No such file or directory
/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>
/*
Include directly the different
headers from cppconn/ and mysql_driver.h + mysql_util.h
(and mysql_connection.h). This will reduce your build time!
*/
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
using namespace std;
int main(void)
{
cout << endl;
cout << "Running 'SELECT 'Hello World!' »AS _message'..." << endl;
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
sql::ResultSet *res;
/* Create a connection */
driver = get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "root", "root");
/* Connect to the MySQL test database */
con->setSchema("test");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
while (res->next()) {
cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
cout << res->getString("_message") << endl;
cout << "\t... MySQL says it again: ";
/* Access column data by numeric offset, 1 is the first column */
cout << res->getString(1) << endl;
}
delete res;
delete stmt;
delete con;
} catch (sql::SQLException &e) {
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " »
<< __LINE__ << endl;
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << " )" << endl;
}
cout << endl;
return EXIT_SUCCESS;
}
I am compliling it in Codeblocks and i have installed mysql connector I am trying it very first time help please !
Upvotes: 1
Views: 7016
Reputation: 99
I am facing the same problem as you, but on MAC on QtCreator. All what I received is: cppconn/connection.h file is not found
.
I am not connected to MySQL Server yet. So I commented all Files, that has something to do with the databank. While building I get:
library -lGL not found
Because the databank was set up on a linux, I had to change the Libraries. So I downloaded first mysql libraries for MAC:
brew install mysql-connector-c++
then I added them in .pro:
mac: {
LIBS += -framework OpenGL
INCLUDEPATH += /usr/local/opt/mysql-connector-c++/include/cppconn
}
after compiling I got the error:
boost/scopped_ptr.hpp file not found
Here I need to install boost:
brew install boost
Then add boost in .pro too:
mac: {
LIBS += -framework OpenGL
INCLUDEPATH += /usr/local/opt/mysql-connector-c++/include/cppconn /usr/local/opt/boost/include
}
Now I am getting again an Error:
symbol(s) not found for architecture x86_64
linker command failed with exit code 1
Update:
So my .pro looks like this at the end:
unix:!macx {
LIBS += -lGL
LIBS += -L/usr/lib -L/usr/lib -lmysqlcppconn
INCLUDEPATH += -I/usr/include -I/usr/local/include -I/usr/local/include/cppconn
}
macx: {
LIBS += -framework OpenGL -L/usr/local/opt/mysql-connector-c++/lib -lmysqlcppconn
INCLUDEPATH += /usr/local/opt/mysql-connector-c++/lib
INCLUDEPATH += /usr/local/opt/mysql-connector-c++/include/cppconn /usr/local/opt/boost/include /usr/local/opt/mysql-connector-c++/include
}
it seemed in the INCLUDEPATH
for macx I needed to mention the missing library which is mysqlcppconn
. The -l
helps to figure out that this is the name of the library.
and it actually do work. Now all what needed is a connection to the server.
Upvotes: 1
Reputation: 192
You are most likely missing libmysqlcppconn-dev. Once installed, the error should disappear.
Upvotes: 5