0

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;
    }
  • 1
    Does this answer your question? [What is an undefined reference/unresolved external symbol error and how do I fix it?](https://stackoverflow.com/questions/12573816/what-is-an-undefined-reference-unresolved-external-symbol-error-and-how-do-i-fix) – Richard Critten Nov 29 '20 at 12:07
  • I didn't manage to find the answer in that link, as It seems to find the libraries but for some reason, I get an error with `get_driver_instance()`, if it is not present it compiles and executes with a segmentation fault though – Andrew Savastysnov Dec 02 '20 at 17:35

0 Answers0