MinGW environment add MySQL development library

Source: Internet
Author: User

Today happens to be using MySQL for development in the Windows MinGW platform.

0. Download MySQL

Http://cdn.mysql.com/Downloads/MySQL-5.1/mysql-noinstall-5.1.73-win32.zip

Download this green version of the. Then unzip to the D disk, copy an INI configuration file, modify some options, and start the service, read more about my previous blog

Http://www.cnblogs.com/wunaozai/p/3641589.html

1. Development after the installation is done, the following is an example program

1#include <stdio.h>2#include <windows.h>3#include <mysql.h>4#include <winsock2.h>5 6 intMainintargcChar*argv[])7 {8 MYSQL Conn;9     intRes;TenMysql_init (&conn); One     if(Mysql_real_connect (&conn,"localhost","Root","","Test",0, null,client_found_rows))//"root": Database Administrator "": Root Password "test": Name of the database A     { -printf"Connect success!\n"); -Res=mysql_query (&conn,"INSERT into test values (' user ', ' 123456 ')"); the         if(RES) -         { -printf"error\n"); -         } +         Else -         { +printf"ok\n"); A         } atMysql_close (&conn); -     } -     return 0; -}

To copy the include in the MySQL installer to the development environment. Then there is a static link library that constructs a LIBMYSQL.A.
The official MySQL win release version is compiled by VC, the resulting LIB cannot be mingw linked. An undefined error is thrown when linking.

The specific approach is to copy the Libmysql.def to the Lib directory in the Include folder and execute the following sentence in the Lib directory

Dlltool--input-def libmysql.def--dllname libmySQL.dll--output-lib libmysql.a-k (Dlltool tool is MinGW comes with)

A LIBMYSQL.A file is generated. And then copy this file into the development environment, which is basically possible.

After we've done this, we'll compile it.

g++ main.cpp-o main.exe-iinclude-l.-lws2_32-lmysql

This is the kind of mistake that happens.

c:\docume~1\admini~1\locals~1\temp\cc8hizra.o:main.cpp: (. text+0x68): Undefined reference to ' [email protected]4'c:\docume~1\admini~1\locals~1\temp\cc8hizra.o:main.cpp: (. text+0xb1): Undefined reference to ' [email protected] +'c:\docume~1\admini~1\locals~1\temp\cc8hizra.o:main.cpp: (. text+0XDF): Undefined reference to ' [email protected]8'c:\docume~1\admini~1\locals~1\temp\cc8hizra.o:main.cpp: (. text+0x11d): Undefined reference to ' [email protected]4'Collect2.exe:error:ld returned1Exit Statusmake:[Main] Error1

Resolved as follows
Open Libmysql.def Modify the corresponding error place as

Like this, manually increment the number in the back, then repeat the above operation, and re-create the LIBMYSQL.A link library with Dlltool

You can use it here.

Resources

Http://www.cnblogs.com/cy163/archive/2009/10/03/1577812.html

MinGW environment add MySQL development library

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.