2012-04-20 2 views
7

해결 방법 : 동일한 문제가있는 사람들을위한 단계별 지침을 만들기로 결정했습니다. 이 모든 것이 완전히 수정되는지는 모르겠지만 제공 할 코드 조각을 컴파일 할 수 있습니다. 오류가 있으면 수정 해주십시오. 이것은 대부분 실패한 시도에서 포기하고 솔직한 사람들을 돕기위한 것이기 때문에 전체 과정을 문서화해야합니다. 긴 게시물에 대한 죄송합니다 : Pwindows 2010 용 mysql 커넥터/C++가 컴파일되지 않음

STEP BY STEP FOR SETTING UP MYSQL CONNECTOR/C++ FOR 2010 MICROSOFT VISUAL C++ EXPRESS: 
FILES NEEDED: 
Windows x86 32 Bit ZIP: Connector/C++ -> http://dev.mysql.com/downloads/connector/cpp/ 
Windows X86 32 Bit ZIP: Connector/C -> http://dev.mysql.com/downloads/connector/c/ 
BOOST -> http://www.boost.org/users/download/ 

The reason why 62bit doesn't work is because you are using the express edition. After you have downloaded all those files, extract them. I keep mine in C (for ease of access). Now open up MVC++ 2010 EXPRESS. 
File -> New -> Project 
Win32 Console Application 
Next 
Check Empty project 
Finish 
Create your first .cpp. I call mine main.cpp 
Project -> Properties 
C/C++ -> General -> Additional Include Directories -> C:\mysql-connector-c++-noinstall-1.1.0-win32\mysql-connector-c++-noinstall-1.1.0-win32\include 
C/C++ -> General -> Additional Include Directories -> C:\mysql-connector-c++-noinstall-1.1.0-win32\mysql-connector-c++-noinstall-1.1.0-win32\include\cppconn 
C/C++ -> General -> Additional Include Directories -> C:\boost_1_49_0 
Linker -> General -> Additional Library Directories -> C:\mysql-connector-c++-noinstall-1.1.0-win32\mysql-connector-c++-noinstall-1.1.0-win32\lib 
Linker -> General -> Additional Library Directories -> C:\mysql-connector-c-noinstall-6.0.2-win32\mysql-connector-c-noinstall-6.0.2-win32\lib 
The reason why we downloaded the Connector/C is because it has two files we need: libmysql.lib and libmysql.dll 
Linker -> Input -> Additional Dependencies -> mysqlcppconn.lib 
Linker -> Input -> Additional Dependencies -> libmysql.lib 

If you change to Release, youll have to enter in the information again. 
In your main.cpp place the following code and build it: 

=

/* 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 <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", "YOUR USERNAME", "YOUR PASSWORD"); 
    /* Connect to the MySQL test database */ 
    con->setSchema("YOUR DATABASE"); 

    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; 

int a;  // hangs 
cin >> a; 

return EXIT_SUCCESS; 
} 

당신은 int8_t에 대한 오류를 얻어야한다. c : \ mysql-connector-C++ - noinstall-1.1.0-win32 \ mysql-connector-C++ - noinstall-1.1.0-win32 \ include \ cppconn \ config.h에있는 config.h를 두 번 클릭하십시오. 그것을 두 번 클릭하십시오. 컴파일러가 빌드를 출력하는 폴더 안에 libmysql.dll (Connector/C 내부)과 mysqlcppconn.dll (Connector/C++ 내부)을 놓습니다. 완료되면 저장하고 실행하십시오. http://blog.ulf-wendel.de/?p=215 하지만 여전히 컴파일 오류가 점점 오전 :

OLD 게시물 내가 그대로 본 사이트의 단계를 따라했습니다

봐니까. 나는 라이브러리를 연결하거나 디렉토리를 포함하는 것이 새로운 것은 아니지만, 2010 년 Express와 함께 mysql connector/C++로 응용 프로그램을 만든 새로운 수퍼 영웅을 사용하여 간단한 KISS 예제를 만들 수 있습니다. 나는 하루 종일 내 치아를 연마하고있다. I이도 따랐다 : http://www.tidytutorials.com/2009/07/mysql-connector-c-example-windows-clexe.html 업데이트

1>main.obj : error LNK2019: unresolved external symbol __imp__get_driver_instance referenced in function _main 

#include <stdlib.h> 
#include <iostream> 
using namespace std; 
#include <cppconn/driver.h> 
#include <cppconn/exception.h> 
#include <cppconn/resultset.h> 
#include <cppconn/statement.h> 
#include <cppconn/prepared_statement.h> 

int main(){ 

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

    try{ 
     driver = get_driver_instance(); 
     con = driver->connect("tcp://127.0.0.1:3306", "root", "root"); 
     con->setSchema("foxlogin"); 

     stmt = con->createStatement(); 
     stmt->execute("insert into example values(4,'four'),(5, 'five')"); 
     delete stmt; 

     pstmt = con->prepareStatement("select * from example"); 
     res = pstmt->executeQuery(); 
     while (res->next()) 
      std::cout<<res->getInt("id")<<" "<<res->getString("data")<<std::endl; 
     delete res; 
     delete pstmt; 

     pstmt = con->prepareStatement("delete from example where id=?"); 
     pstmt->setInt(1,4); 
     pstmt->executeUpdate(); 
     pstmt->setInt(1,5); 
     pstmt->executeUpdate(); 

     delete pstmt; 

     delete con;  
    }catch(sql::SQLException &e){ 
     std::cout<<e.what(); 
    } 

    int a;  // hang 
    cin >> a; 

    return 0; 
} 

변화 (데이터베이스) 예 소스 http://forums.mysql.com/read.php?167,492097,492097#msg-492097는 I 심지어 C++, 각각 64 BOTH 테스트와 함께 C 커넥터 (별도 빌드)을 사용하고 32 비트 버전 (총 4 가지 테스트). 나는 부스트를 다운로드하고 그것을 연결했다. 내가 사용하고있는 새로운 코드는 공식 mysql 웹 사이트에서 올 것이다. 두 빌드 모두 동일한 오류가 발생합니다. 64 TEST에 대한

/* 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 <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: erthwrthj, Configuration: Debug Win32 ------ 
    1> main.cpp 
    1>c:\mysql c++ 64\include\cppconn\sqlstring.h(36): warning C4251: 'sql::SQLString::realStr' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'sql::SQLString' 
    1>   with 
    1>   [ 
    1>    _Elem=char, 
    1>    _Traits=std::char_traits<char>, 
    1>    _Ax=std::allocator<char> 
    1>   ] 
    1>c:\mysql c++ 64\include\mysql_connection.h(156): warning C4251: 'sql::mysql::MySQL_Connection::proxy' : class 'boost::shared_ptr<T>' needs to have dll-interface to be used by clients of class 'sql::mysql::MySQL_Connection' 
    1>   with 
    1>   [ 
    1>    T=sql::mysql::NativeAPI::NativeConnectionWrapper 
    1>   ] 
    1>c:\mysql c++ 64\include\cppconn\exception.h(59): warning C4251: 'sql::SQLException::sql_state' : class 'std::basic_string<_Elem,_Traits,_Ax>' needs to have dll-interface to be used by clients of class 'sql::SQLException' 
    1>   with 
    1>   [ 
    1>    _Elem=char, 
    1>    _Traits=std::char_traits<char>, 
    1>    _Ax=std::allocator<char> 
    1>   ] 
    1>c:\mysql c++ 64\include\cppconn\config.h(60): error C2371: 'int8_t' : redefinition; different basic types 
    1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(17) : see declaration of 'int8_t' 
    1>c:\mysql c++ 64\include\cppconn\config.h(60): error C2371: 'int8_t' : redefinition; different basic types 
    1>   c:\program files (x86)\microsoft visual studio 10.0\vc\include\stdint.h(17) : see declaration of 'int8_t' 
    1>c:\users\null\documents\visual studio 2010\projects\erthwrthj\erthwrthj\main.cpp(74): error C2146: syntax error : missing ';' before identifier '»' 
    1>c:\users\null\documents\visual studio 2010\projects\erthwrthj\erthwrthj\main.cpp(74): error C2065: '»' : undeclared identifier 
    ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ========== 

도움을 주시면 감사하겠습니다 (I의 힘은 32 비트 빌드 오류 테스트를 포함, 당신이 필요로하는 경우 아픈 제공)!

업데이트 2 : view_findpost_ 페이지 _1474626 "> http://www.dreamincode.net/forums/topic/253647-question-regarding-connecting-to-mysql-50-using-visual-studio-2010/ page_ 보기 _findpost_ p _1474626이 사람은 config.h가 int8_t에 대한 #typedef가 있기 때문에 config.h가 stdint.h와 충돌하기 때문이라고 생각하는 것 같습니다.이 해결책이 있어야합니다. 로컬 MySQL 데이터베이스에 연결할 수있는 다른 라이브러리 (무료)도 가져 가야하지만 모두를 돕기 위해이 정보를 알아내는 것이 정말로 마음이 아 닙니다.

+0

당신이 libmysql.lib 위해 추가 라이브러리 의존성을 추가하려고 했나 cppcon/config.h의 파일의 모든 형식 정의의의를 언급하는 것입니다? 여기에서 다운로드 할 수 있습니다. http://dev.mysql.com/downloads/connector/c/ –

+0

예.이것은 그것이 작동하도록하는 나의 두 번째 벤처 기업이다. 그리고 두 번째로 길을 잃었습니다. – user1328762

+1

'62bit가 작동하지 않는 이유 '는 실제로 출력물에서 복사 & 붙여 넣기 였나요? 나는 마이크로 소프트의 누군가가 그런 잘못된 진술을 썼다는 것에 놀라지 않을 것이다. 그러나 나는 궁금해했다. 당신의 질문이 "해결책"으로 시작하는 이유는 무엇입니까? 실무 답변을했다면 자신의 질문에 대한 답을 써야합니다. –

답변

0

C++ 및 MySQL 커넥터에 대한 많은 질문이 있으므로 재현하다 그것을 열심히하기 위해 열심히, 나는 1 년 전에 질문 받았다고해도이 질문에 답할 것입니다.

솔루션은 매우 간단합니다, 당신이해야 할 유일한 것은

관련 문제