Panel użytkownika
Nazwa użytkownika:
Hasło:
Nie masz jeszcze konta?

[MySQL Connector]Compile error

Ostatnio zmodyfikowano 2012-07-31 22:47
Autor Wiadomość
marcin107
Temat założony przez niniejszego użytkownika
[MySQL Connector]Compile error
» 2012-07-31 18:13:10
Witam, kiedy próbowałem skompilować ten kod mam kilka błędów.
C/C++
/* Copyright 2008, 2010, Oracle and/or its affiliates. All rights reserved.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.

There are special exceptions to the terms and conditions of the GPL
as it is applied to this software. View the full text of the
exception in file EXCEPTIONS-CONNECTOR-C++ in the directory of this
software distribution.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

/* Standard C++ includes */
#include <stdlib.h>
#include <iostream>
#include "StdAfx.h"

/*
  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 fata 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;
}

1>------ Build started: Project: new2, Configuration: Release Win32 ------
1>new2.obj : error LNK2011: precompiled object not linked in; image may not run
1>new2.obj : error LNK2001: unresolved external symbol _get_driver_instance
1>C:\Users\xxx\Desktop\programowanie\new2\Release\new2.exe : fatal error LNK1120: 2 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Proszę was o pomoc.
P-61510
xevuel
» 2012-07-31 18:17:07
Wedle wszelkiego prawdopodobieństwa, oraz tego oto linku: http://forums.mysql.com/read.php?167,244004,244004#msg-244004 podejrzewam, że nie dodałeś pliku mysqlcppconn.lib do linkera :)
P-61511
marcin107
Temat założony przez niniejszego użytkownika
» 2012-07-31 18:21:18
Niestety, ale w linker --> Input --> Additional Dependencies posiadam dopisane 3 linijki: mysqlcppconn-static.lib, libmysql.lib, mysqlcppconn.lib, oczywiście po każdym .lib nie ma przecinka, jest tylko enter.
P-61512
xevuel
» 2012-07-31 18:22:19
Cytat z http://dev.mysql.com/doc/refman/5.1/en/ccpp-news-1-1-0.html:
get_driver_instance() is now only available in dynamic library builds - static builds do not have this symbol. This was done to accommodate loading the DLL with LoadLibrary or dlopen. If you do not use CMake for building the source code you will need to define mysqlcppconn_EXPORTS if you are loading dynamically and want to use the get_driver_instance() entry point.
Używasz DLL-ek z programem, czy nie?

//edit:

@DejaVu:
Ale według tego stwierdzenia:
get_driver_instance() is now only available in dynamic library builds - static builds do not have this symbol.
uznaję, że po prostu biblioteki, które są linkowane statycznie nie mają w sobie tej funkcji.
 
Mimo wszystko trzeba jakiegoś liba dolinkować.
Wiadomo, że w większości przypadków do używania DLL'ek też trzeba dolinkować liba, ale nie zawiera on wtedy funkcji, a tylko miejsca, gdzie są umieszczone w DLL'ce. Pewnie po prostu twórcy stworzyli dwa różne buildy dla dwóch typów linkowania biblioteki :)
P-61513
DejaVu
» 2012-07-31 18:25:46
@up: dll-ki nie mają nic do rzeczy. Mimo wszystko trzeba jakiegoś liba dolinkować. DLL-ka będzie musiała leżeć koło exe ale dopiero po tym jak uda mu się to skompilować. Na chwilę obecną jest ona zbędna.
P-61515
marcin107
Temat założony przez niniejszego użytkownika
» 2012-07-31 18:32:21
Może jakiś błąd przy instalacji? Pobrałem wersję bin, z której po prostu się instalowało i stosowałem się do tego http://dev.mysql.com/doc/refman/5.5/en/connector-cpp-apps-windows-visual-studio.html.
A wg tego http://dev.mysql.com/doc/refman/5.5/en/connector-cpp-installation-binary.html
"Your application should use the same linker configuration as MySQL Connector/C++, for example use one of /MD, /MDd, /MT, or /MTd." - O co z tym w ogóle chodzi?

A może ktoś skusi się na pisanie kursów, poradników do MySQL Connectora?
P-61516
DejaVu
» 2012-07-31 21:48:56
Nie ma sensu pisać kursów do MySQL Connector-a dla C++, ponieważ to jest jeden wieli bug. Lepiej używać API napisanego w C, które działa (w przeciwieństwie do tego w C++).
P-61544
marcin107
Temat założony przez niniejszego użytkownika
» 2012-07-31 22:47:54
Bardzo różni się C od C++? To może się pobawię w konsoli z tym wszystkim.
P-61551
« 1 »
  Strona 1 z 1