2013-08-27 2 views
2

Я пытаюсь получить рабочий пример MySQL с Visual Studio 2010 в Windows 7 (x64). У меня нет проблем в Linux, однако я получаю много ошибок в Windows. Это мой код (я скопировал с какой-либо сайт, чтобы проверить, если он на самом деле не будет работать)C++ mySQL connector LINKER errors (Windows)

/* 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 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 <driver.h> 
#include <exception.h> 
#include <resultset.h> 
#include <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; 
} 

курица я попытался ссылки на статические библиотеки mysqlcppconn-static.lib. Ниже приводятся неурегулированные ошибки. :

1>xedownload.obj : error LNK2019: unresolved external symbol  
"__declspec(dllimport)  public: class std::basic_string<char,struct  
std::char_traits<char>,class std::allocator<char> > const & __thiscall  
sql::SQLException::getSQLState(void)const "([email protected]@[email protected]@[email protected][email protected]@[email protected]@V?$alloc [email protected]@[email protected]@[email protected]@XZ) referenced in function __catch$_main$0 
1>xedownload.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) 
public: int __thiscall sql::SQLException::getErrorCode(void)const "([email protected]@[email protected]@QBEHXZ) referenced in function __catch$_main$0 
1>xedownload.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) 
public: __thiscall sql::SQLString::~SQLString(void)" ([email protected]@@[email protected])  referenced in function _main 
1>xedownload.obj : error LNK2019: unresolved external symbol "__declspec(dllimport)  public: __thiscall sql::SQLString::SQLString(char const * const)" ([email protected]@@[email protected]@Z) referenced in function _main 
1>xedownload.obj : error LNK2019: unresolved external symbol __imp__get_driver_instance referenced in function _main 
1>xedownload.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::basic_string<char,struct std::char_traits<char>,class  std::allocator<char> > const & __thiscall sql::SQLString::asStdString(void)const " ([email protected]@[email protected]@[email protected][email protected]@[email protected]@[email protected]@[email protected]@[email protected]@XZ) referenced in function "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl std::operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class sql::SQLString const &)" ([email protected]@[email protected][email protected]@[email protected]@@[email protected]@[email protected]@@@Z) 
1>c:\users\avi\documents\visual studio 2010\Projects\xedownload\Debug\xedownload.exe : fatal error LNK1120: 6 unresolved externals 

ответ

0

Я думаю, что вы работаете в win32, но на самом деле ваша библиотека 64-разрядная, так что вы должны видеть вашу систему установлен MySQL Connector C++ 1.1.6, в котором рядом, в конце концов, является 64- бит или 32-бит. Для запуска 32-разрядной программы требуется установка 32-разрядной библиотеки, для которой требуется 64-разрядные библиотеки и файлы заголовков для запуска 64-разрядных программ. VSxxxx особое внимание уделяется процессу разработки