2016-03-30 11 views
0

Visual Studio 2013'te C++ ile mysql bağlanmaya çalışıyorum. Release Configuration'ı kullanıyorum. Zaten dizinleri koymakVisual Studio 2013'te C++ ile mysql bağlanmaya çalışırken çözülmeyen externals

C: \ mysql-5.7.11-WINX64 \ C lib: \ Program Files \ MySQL \ Connector.C++ 1.1 \ C şunlardır: C/C++ genel olarak \ boost_1_60_0

-> Ek Bağımlılıklar, VC++ Dizinleri ve Bağlayıcı genel-> Ek Bağımlılıklar

ve ayrıca Bağlayıcı -> Giriş'e mysqlcppconn-static.lib ve libmysql.lib ekledik.

Ve şimdi hata LNK1120 bir hata alıyorum: 2 externals çözülmeyen
hata LNK2001:
hata LNK2001 _get_driver_instance çözülmemiş dış simge: çözülmemiş dış simge _WinMain 16

@ ben bu nasıl düzeltebilirim? Teşekkürler!

/* 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> 
#include <cppconn/prepared_statement.h> 

using namespace std; 

int main(void) 
{ 
cout << endl; 
cout << "Let's have MySQL count from 10 to 1..." << endl; 

try { 
    sql::Driver *driver; 
    sql::Connection *con; 
    sql::Statement *stmt; 
    sql::ResultSet *res; 
    sql::PreparedStatement *pstmt; 

    /* 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(); 
    stmt->execute("DROP TABLE IF EXISTS test"); 
    stmt->execute("CREATE TABLE test(id INT)"); 
    delete stmt; 

    /* '?' is the supported placeholder syntax */ 
    pstmt = con->prepareStatement("INSERT INTO test(id) VALUES (?)"); 
    for (int i = 1; i <= 10; i++) { 
    pstmt->setInt(1, i); 
    pstmt->executeUpdate(); 
    } 
    delete pstmt; 

    /* Select in ascending order */ 
    pstmt = con->prepareStatement("SELECT id FROM test ORDER BY id ASC"); 
    res = pstmt->executeQuery(); 

    /* Fetch in reverse = descending order! */ 
    res->afterLast(); 
    while (res->previous()) 
    cout << "\t... MySQL counts: " << res->getInt("id") << endl; 
    delete res; 

    delete pstmt; 
    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; 
} 

cevap

1

Birkaç sorunla karşılaşıyorsunuz.

  1. ilk sembolü yerine main ait [email protected] bulmaya çalışırken kanıtladığı gibi proje ayarları Windows uygulaması değil, bir konsol uygulaması bekliyor gibi görünen olmasıdır. Proje ayarlarınızı iki kez kontrol edin.

  2. İkincisi, statik olarak bağlantı kurmaya çalıştığınız, ancak en azından bazı mysql sürümlerinde, kodunuzun geri kalanında sembollerin görünmesi için bir önişlemci yönergesi tanımlamanız gerektiğidir. Spesifik olarak, _get_driver_instance(), çünkü bu, mysql kütüphanelerine dinamik olarak bağlananlar için eklenen bir işlevdi. Proje ayarlarında mysqlcppconn_EXPORTS tanımlamayı deneyin ve yeniden oluşturun.

İlgili konular