VC Connection MySQL Database error: libmysql.lib:fatal error lnk1113:invalid Machine solution

Source: Internet
Author: User
Tags rowcount

VC connection MySQL configuration process in the previous blog post, but when you set up to think that everything is OK, the run has this error: Libmysql.lib:fatal error lnk1113:invalid machine type. Invalid machine type, really is very people catch urgent.

The reason for this error is that I installed a 64bit MySQL server on win8.1, and I compiled a 32-bit VC program that is connected to a 64-bit libmysql.lib library, so it will produce "invalid machine type (invalid)" The error prompt.

The solution for this "error LNK1113" Bug is:

Download the 32-bit MySQL zip package for about 100 m of that. Unzip out, the Lib directory in accordance with the 4th step to locate Lib. In this case, when our 32-bit program compiles, the link is the 32-bit library, there will be no link error above. You do not have to switch to the XP system to operate.

Environment Description:

Operating system: Windows 8.1

Development tools: vc++6.0

Development of the EXE:32-bit program

Database server: 64-bit mysql-5.5

Refer to the database lib:32 bit of mysql-5.7.10-win32.zip (320M) of the Lib folder.

The steps are as follows:

1. Download the MySQL installation package to the official website www.mysql.com:

Mysql-5.7.10-win32.zip Address: http://dev.mysql.com/downloads/mysql/

Of course you can also download and install Mysql*.msi.

2. install MySQL, in the installation process (if the. msi installation), be sure to select the C include Files/lib Files, so that after installation in the MySQL installation folder to find the Include and Lib folders, These folders will be used in the following operations.

3. Copy and copy the Libmysql.dll under the D:\Mysql32\mysql-5.7.10-win32\lib to C:\WINDOWS\system32. (This step I did not do, the same can be compiled through, I was WIN8.1 under the verification, I do not know whether in XP or win-nt need this step).

4. This is also the most critical step! Open: Tools, Options menu, find the "directory" tab , you can see there is a: "Show directory as" drop-down box, select the Library files option, add: "32-bit MySQL zip decompression folder" \ MySQLServer 5.7\lib\,

You can see me, this is a 32-bit lib.

5. Compile and run, success.

Only need to replace the 64-bit LIB with 32-bit LIB, so that when our 32-bit program compiles, the link is 32-bit library, there will be no link error above.

The solution is still very simple, is the download Zip package is too slow ....

Test.cpp:Defines the entry point for the console application.//#include <stdio.h> #include <windows.h> #inc Lude "StdAfx.h" #include <winsock.h> #include <iostream> #include <string> #include <mysql.h> u  Sing namespace std; #pragma comment (lib, "Ws2_32.lib")//#pragma comment (lib, "Libmysql.lib")//Comment off//#define STEPBYSTEP void without stepping into debug      Pause () {#ifdef stepbystep system ("pause");       #endif} void WriteToFile (const char *s) {FILE *fp=fopen ("Info.txt", "RW");       fprintf (Fp,s);    Fclose (FP);       }/* int main () {MySQL mysql; Mysql_init (&mysql);              Initialize MySQL structure if (!mysql_real_connect (&mysql, "localhost", "myuser", "123456", "student_db", 3306,null,0))       printf ("\ nthe error!\n when connecting to the database");       else printf ("\ nthe connection database succeeded!\n"); Mysql_close (&mysql); Release the database return 0;}      */int Main (int argc, char* argv[]) {cout<< "Start ..." <<endl;   Pause ();   MySQL MySQL;        if (0==mysql_library_init (0,null,null)) {cout<< "Mysql_library_init succeed" <<endl;          }else{cout<< "Mysql_library_init failed" <<endl;      return-1;      } pause ();      if (Null!=mysql_init (&mysql)) {cout<< "Mysql_init succeed" <<endl;          }else{cout<< "Mysql_init failed" <<endl;      return-1;      } pause (); if (0==mysql_options (&mysql,mysql_set_charset_name, "gb2312")) {cout<< "mysql_option succeed" <&      Lt;endl;          }else{cout<< "Mysql_option failed" <<endl;      return-1;        } pause (); if (Null!=mysql_real_connect (&mysql, "localhost", "myuser", "123456", "student_db", 3306,null,0)) {cout<      < "Mysql_real_connect Succeed" <<endl;          }else{cout<< "Mysql_real_connect failed" <<endl;      return-1;      } pause (); StriNg SQL;      Sql= "SELECT * from Sgroup";      Mysql_res *result=null;              if (0==mysql_query (&mysql,sql.c_str ())) {cout<< "mysql_query select Succeed" <<endl;              Result=mysql_store_result (&mysql);              int rowcount=mysql_num_rows (result);              cout<< "Row count:" <<rowcount<<endl;              unsigned int fieldcount=mysql_num_fields (result);              Mysql_field *field=null;                  for (unsigned int i=0;i<fieldcount;i++) {field=mysql_fetch_field_direct (result,i);              cout<<field->name<< "\t\t";              } cout<<endl;              Mysql_row Row=null;              Row=mysql_fetch_row (result); while (Null!=row) {for (int i=0;i<fieldcount;i++) {Cout<<ro                    w[i]<< "\t\t";           } cout<<endl;       Row=mysql_fetch_row (result);              }}else{cout<< "mysql_query Select data Failed" <<endl;              Mysql_close (&mysql);      return-1;      } pause ();      /*sql= "drop table User_info";       if (0==mysql_query (&mysql,sql.c_str ())) {cout<< "mysql_query drop table Succeed" <<endl;              }else{cout<< "mysql_query drop table Failed" <<endl;              Mysql_close (&mysql);        return-1;      } */Mysql_free_result (result);      Mysql_close (&mysql);          Mysql_server_end ();      System ("pause");  return 0;  }

  

VC Connection MySQL Database error: libmysql.lib:fatal error lnk1113:invalid Machine solution

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.