views:

172

answers:

1

Hello, I'm wondering if anyone can help me on getting my visual studio c++ project setup correctly to work with MySql?

I downloaded and installed MySql Server, and installed the developer content with the include files, but beyond that I'm a bit lost.

I tried adding the 'include' directory in my MySql install path to my additional includes directory, which allowed me to access the includes I needed, but left me with unresolved external symbol errors.

1>Main.obj : error LNK2019: unresolved external symbol _mysql_error@4 referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol _mysql_real_connect@32 referenced in function _main

Any help would be greatly appreciated.

+1  A: 

Sounds like the library isn't being included. The first thing I would look at is Additional Dependencies. You can either set it programatically or in Visual Studio (Solution->Properities->Configuration Properties-> Linker

You may need to include the library under "additional library directories" in that same area.

Jeremy Morgan
This didn't help at first, I went in and added libmysql.lib as an additional dependency and got it to compile correctly.I took the libmysql.dll from my mysql's lib/debug (im compiling in debug atm, test application) folder and put it in the executable dir, the program simply starts and crashes instantly:Unhandled exception at 0x76ff8c39 in SqlTest.exe: 0xC0000005: Access violation writing location 0x00000014.This is the code: connection = mysql_real_connect( if (connection == NULL) { cout << mysql_error(
Undawned
Well, you are one step closer, at least it's linking the libraries now. I have feeling its in the linking there are still some problems. I would still include it under the additional directories if you haven't done so already. Since this is an unhandled exception, wrap it up with a try-catch and see if you can catch the exception and see what it is. This should get you closer to fixing it. As a note, I would only use try-catch to get the exception and then fix the problem. Do not rely on it for program flow.
Jeremy Morgan
Thanks for all your help, I have resolved the problem it appears I was using some bad code for my test code, grabbed the code from http://dev.mysql.com/doc/refman/5.0/en/mysql-real-connect.html and all went well.
Undawned
Glad you got it working!
Jeremy Morgan