简体   繁体   中英

Static linking of MySQL in C/C++

I am trying to develop an application that uses MySQL using C++. I downloaded the library from their website and I have attempted to compile the following code:

#include <iostream>
#include <windows.h>
#include <mysql.h>
using namespace std;
int main()
{
    MYSQL *connection, mysql;
    MYSQL_RES *result;
    MYSQL_ROW row;
    mysql_init(&mysql);
}

The line that has mysql_init(&mysql); gives me a compilation error

undefined reference to `mysql_init@4'

I am guessing this is due to a library error. I am linking mysqlclient.lib and libmysql.lib in that order. What do I need to do to make this compile without requiring a dll file? Is that possible? Thank you. Note: I am using mingw32 on Windows 7 x64 to develop an application for Windows.

Maybe this link will help. It states that mysqlclient.lib is the static library and libmysql.lib is the dynamic library, so I don't think you should be linking both.

http://dev.mysql.com/doc/refman/5.0/en/building-clients.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM