3

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.

llk
  • 2,501
  • 7
  • 36
  • 43

1 Answers1

4

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

rushman
  • 532
  • 2
  • 8
  • It did, however after removing one of the two links I still receive the same error :( – llk Nov 02 '11 at 11:05
  • Are you compiling your code for 64-bit but using a 32-bit version of the MySQL library to link it? – rushman Nov 03 '11 at 08:37
  • I am compiling 32 using 64bit libs. I got the 32 libs and I can only manage to compile the program when I use both `mysqlclient.lib` and `libmysql.lib` but then it won't launch without `libmysql.dll`, my goal is to make it statically linked. Any ideas? – llk Nov 04 '11 at 04:06
  • I compiled and linked your program here and only needed the mysqlclient.lib library. I did also need to set the /MT option (Release) and the /MTd option (Debug). I used the 32-bit libraries. – rushman Nov 06 '11 at 10:30