2012-04-20 13 views
7

संकलन संकलित नहीं करता है समाधान: मैंने एक ही मुद्दे वाले लोगों के लिए एक चरण-दर-चरण मार्गदर्शिका बनाने का निर्णय लिया है। मुझे नहीं पता कि यह सब कुछ ठीक से ठीक करता है लेकिन यह आपको प्रदान किए गए कोड स्निपेट को संकलित करने देता है। अगर कोई त्रुटि है तो कृपया टिप्पणी करें ताकि मैं उन्हें ठीक कर सकूं। इसका उद्देश्य उन लोगों की मदद करना है जिन्होंने अधिकतर विफल प्रयासों से छूट दी है, और स्पष्ट होने के लिए, पूरी प्रक्रिया को दस्तावेज किया जाना चाहिए था। लंबे समय तक इस पद के लिए क्षमा करें: पीविंडोज़ 2010 के लिए माइस्क्ल कनेक्टर/सी ++

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 के लिए त्रुटियों को मिलना चाहिए। Config.h पर डबल क्लिक करें: c: \ mysql-connector-C++ - noinstall-1.1.0-win32 \ mysql-connector-C++ - noinstall-1.1.0-win32 \ \ cppconn \ config.h शामिल है। इसे लाने के लिए इसे डबल क्लिक करें। अब केवल सभी टाइपिफ़ाफ़ों पर टिप्पणी करें, केवल 8 होना चाहिए। कंपाइलर आपके निर्माण को आउटपुट करने वाले फ़ोल्डर के अंदर libmysql.dll (कनेक्टर/सी के अंदर) और mysqlcppconn.dll (कनेक्टर/सी ++ के अंदर) रखें। जब बचाया और चलाया। http://blog.ulf-wendel.de/?p=215 लेकिन मैं अभी भी एक संकलन त्रुटि हो रही है:

पुरानी पोस्ट देखो

मैं शब्दशः इस साइट पर चरणों का पालन किया नहीं है। मैं पुस्तकालयों को जोड़ने या निर्देशिकाओं को जोड़ने के लिए नया नहीं हूं, लेकिन मैं एक नया सुपर नायक का उपयोग कर सकता हूं जिसने एक साधारण केआईएसएस उदाहरण बनाने के लिए 2010 एक्सप्रेस के साथ MySQL कनेक्टर/सी ++ के साथ अनुप्रयोग बनाये हैं। मैं पूरे दिन अपने दांत पीस रहा हूँ। उदाहरण स्रोत: 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 मैं भी सी ++, और सी कनेक्टर्स (अलग बनाता है) प्रत्येक 64 के साथ दोनों परीक्षणों के साथ इस्तेमाल किया और 32 बिट संस्करण (कुल 4 परीक्षण)। मैंने बूस्ट डाउनलोड किया है और इसे लिंक किया है। मैं जिस नए कोड का उपयोग कर रहा हूं, वह नीचे पोस्ट करेगा जो आधिकारिक mysql वेबसाइट से आता है। दोनों समान त्रुटियों का निर्माण करते हैं।

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

64 टेस्ट द्वारा बनाए जाने वाले त्रुटियों: (मैं सहारे 32 बिट का निर्माण त्रुटि परीक्षण शामिल हैं, अगर आप की जरूरत है बीमार प्रदान)

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 ========== 

मदद की सराहना की होगी!

अद्यतन 2: view_findpost_ पी _1474626 "> http://www.dreamincode.net/forums/topic/253647-question-regarding-connecting-to-mysql-50-using-visual-studio-2010/ पेज_ देखें _findpost_ पी _1474626 इस लड़के को ऐसा लगता है क्योंकि config.h संकलन पर stdint.h के साथ संघर्ष करता है क्योंकि config.h में int8_t के लिए #typedef है। इसके लिए एक समाधान होना चाहिए। यहां तक ​​कि किसी अन्य पुस्तकालय (फ्री) को भी ले जाएं जो स्थानीय MySQL डेटाबेस से कनेक्ट हो सकता है, लेकिन मैं वास्तव में इसे बाहर निकालने में मदद करने के लिए उत्सुक हूं।

+0

आप libmysql.lib के लिए एक अतिरिक्त पुस्तकालय निर्भरता को जोड़ने का प्रयास किया है? आप इसे यहां से डाउनलोड कर सकते हैं: http://dev.mysql.com/downloads/connector/c/ –

+0

हां।यह मेरा दूसरा उद्यम है जो इसे काम करने की कोशिश कर रहा है। और दूसरी बार मैंने खो दिया है। – user1328762

+1

'कारण 62 बिट काम नहीं करता है' क्या वह वास्तव में आउटपुट से कॉपी और पेस्ट था? मुझे आश्चर्य नहीं होगा कि माइक्रोसॉफ्ट में किसी ने ऐसा गलत कथन लिखा था, लेकिन मैं सोच रहा था ... आपका प्रश्न "समाधान" से क्यों शुरू हो रहा है? यदि आपके पास एक कामकाजी उत्तर था, तो आपको अपने प्रश्न का उत्तर लिखना चाहिए। –

उत्तर

0

चूंकि सी ++ और MySQL कनेक्टर के बारे में बहुत सारे प्रश्न हैं, और यह है reall मैं इसे काम करने में कठोर हूं, मैं इस सवाल का जवाब दूंगा, यहां तक ​​कि 1 साल पहले भी यह पूछा गया था।

समाधान बहुत आसान है, केवल एक चीज आप करने की ज़रूरत सभी typedef की टिप्पणी करने के लिए cppcon/config.h फ़ाइल

संबंधित मुद्दे