Я новичок в C++ и решил, что единственный способ, которым я собираюсь учиться, - это загрязнить какой-то код. Я пытаюсь создать программу, которая подключается к базе данных mysql. Я использую g ++, на linux. Без идеала.mysql-connector-C++ - 'get_driver_instance' не является членом 'sql :: mysql'
я бегу "сделать", и это моя ошибка:
hello.cpp:38: error: ‘get_driver_instance’ is not a member of ‘sql::mysql’
make: *** [hello.o] Error 1
Вот мой код, включая Makefile. Любая помощь будет отличной! Заранее спасибо
###BEGIN hello.cpp###
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <stdexcept>
#include "mysql_connection.h"
#include <cppconn/driver.h>
#include <cppconn/exception.h>
#include <cppconn/resultset.h>
#include <cppconn/statement.h>
#include <cppconn/prepared_statement.h>
#define EXAMPLE_HOST "localhost"
#define EXAMPLE_USER "root"
#define EXAMPLE_PASS ""
#define EXAMPLE_DB "world"
using namespace std;
using namespace sql::mysql;
int main(int argc, const char **argv)
{
string url(argc >= 2 ? argv[1] : EXAMPLE_HOST);
const string user(argc >= 3 ? argv[2] : EXAMPLE_USER);
const string pass(argc >= 4 ? argv[3] : EXAMPLE_PASS);
const string database(argc >= 5 ? argv[4] : EXAMPLE_DB);
cout << "Connector/C++ tutorial framework..." << endl;
cout << endl;
try {
sql::Driver *driver;
sql::Connection *con;
sql::Statement *stmt;
driver = sql::mysql::get_driver_instance();
con = driver->connect("tcp://127.0.0.1:3306", "user", "password");
stmt = con->createStatement();
stmt->execute("USE " EXAMPLE_DB);
stmt->execute("DROP TABLE IF EXISTS test");
stmt->execute("CREATE TABLE test(id INT, label CHAR(1))");
stmt->execute("INSERT INTO test(id, label) VALUES (1, 'a')");
delete stmt;
delete con;
} catch (sql::SQLException &e) {
/*
The MySQL Connector/C++ throws three different exceptions:
- sql::MethodNotImplementedException (derived from sql::SQLException)
- sql::InvalidArgumentException (derived from sql::SQLException)
- sql::SQLException (derived from std::runtime_error)
*/
cout << "# ERR: SQLException in " << __FILE__;
cout << "(" << __FUNCTION__ << ") on line " << __LINE__ << endl;
/* Use what() (derived from std::runtime_error) to fetch the error message */
cout << "# ERR: " << e.what();
cout << " (MySQL error code: " << e.getErrorCode();
cout << ", SQLState: " << e.getSQLState() << ")" << endl;
return EXIT_FAILURE;
}
cout << "Done." << endl;
return EXIT_SUCCESS;
}
###END hello.cpp###
###BEGIN Make File###
SRCS := hello.cpp
OBJS := $(SRCS:.cpp=.o)
CXXFLAGS := -Wall -pedantic
INCPATHS := -I/home/user/mysql-connector/include/
LIBPATHS := -L/home/user/mysql-connector/lib/ -L/home/user/mysql-connector-c/lib/
LIBS := -static -lmysqlclient -mysqlcppconn-static
EXE := MyExecutable
$(EXE): $(OBJS)
$(CXX) $(OBJS) $(LIBPATHS) $(LIBS) -o [email protected]
.cpp.o:
$(CXX) $(CXXFLAGS) $(INCPATHS) -c $< -o [email protected]
###End Makefile###
В вашем следующем посте, секции выделите код и нажмите на «010101 ». –