When i dont use get_driver_instance
i get segmentation fault.
I'm using linux and installed mysqlserver and connector using console commands. Any ideas how to fix this?
/usr/bin/ld: /tmp/ccXisL1A.o: in function
main': test.cpp:(.text+0x5e): undefined reference to
get_driver_instance' collect2: error: ld returned 1 exit status
#include <stdlib.h>
#include <iostream>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
int main()
{
std::cout << std::endl;
std::cout << "Running Hello World!"<< std::endl;
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", "1234");
/* Connect to the MySQL test database */
con->setSchema("test1");
stmt = con->createStatement();
res = stmt->executeQuery("SELECT 'Hello World!' AS _message");
while (res->next()) {
std::cout << "\t... MySQL replies: ";
/* Access column data by alias or column name */
std::cout << res->getString("_message") << std::endl;
std::cout << "\t... MySQL says it again: ";
/* Access column data by numeric offset, 1 is the first column */
std::cout << res->getString(1) << std::endl;
}
delete res;
delete stmt;
delete con;
}