I am getting undefined reference to 'mysql_suchandsuch@#' messages when trying to link my program with the MySQL libraries supplied with the 5.5 server. When MySQL was installed, I used the default path, which for me on Windows is C:\Program Files\MySQL\MySQL Server 5.5\. Originally, I had thought that the spaces are causing my grief, but I think I’ve correctly worked out how to point to the library path without spaces (still with no luck). If there’s another probable cause, please let me know.
I have reviewed a series of questions on this site trying to resolve my issue…
Using mingw/g++, I have tried to link using the following options, based on my own research as well as suggestions here:
- -L”C:\Program Files\MySQL\MySQL Server 5.5\lib\” -llibmysql.lib
- -L”C:\Program Files\MySQL\MySQL Server 5.5\lib\” -lmysqlclient.lib
- -L”C:\Progra~1\MySQL\MySQLS~1.5\lib\” -llibmysql.lib
- -LC:\Progra~1\MySQL\MySQLS~1.5\lib\ -lmysqlclient.lib
- -L”C:\Progra~1\MySQL\MySQLS~1.5\lib\” -lmysql
In all cases, I have put the -L/-l options at the right-most part of the statement, as I understand this can matter.
I have confirmed the libraries do exist. In the /lib dir, I have libmysql.lib, mysqlclient.lib, and libmysql.dll. I have not tried to link with the .dll, as no tutorial/forum I’ve reviewed suggested that.
I am not using MAKEFILES.
Does anyone have specific experience with g++/MySQL?
The following commands work fine for me using a GCC 4.6.1 from November 2011:
So both linking against the LIB and the DLL do work.
You may get a warning (see Gaffi’s comment). This is because the linker does fuzzy linking for you without you having it specified; normally, it would have failed to link. It is being nice, though, and making it work for you, at the same time warning you about things happening without your having requested them. The way to suppress the warning is to make fuzzy linking explicit:
This is a Cygwin/RedHat/MinGW extension to the linker; the docs are here: