Reputation: 2936
I've been trying to use MySQL and C++ together but can't seem to get started as I cannot seem to gain usage of the relevant libraries.
I am on Win7 using MinGW compiler and working in Netbeans. I have the code:
#include <cstdlib>
#include <iostream>
#include <my_global.h>
#include <mysql.h>
using namespace std;
int main(int argc, char **argv)
{
cout << "MySQL client version: " << mysql_get_client_info();
}
But netbeans cannot find my_global.h or mysql.h. In properties of the project I've linked to the library libmysql.dll. Also present in the same directory is mysqlclient.lib but I can't find a way to link to that as the NetBeans linker doesn't seem to register that extension type.
Any help would be greatly appreciated.
C
---PROGRESS I went into NetBeans' Properties->Build->C++ section and added the include directory of my MySQL installation in the 'Include Directories' section. This has solved the above issue of not finding my_global.h or mysql.h but now it cannot find crtdbg.h...
Actually had crtdbg.h in an old Visual Studio installation, moved it and all the other .h files there over to my MinGW includes folder. Seems to find the .hs now but fails with loads of errors, probably an issue with the Visual Studio .h files not being compatible with MinGW. Back to the drawing board.
Upvotes: 0
Views: 2596
Reputation: 26910
Set the include directories, mate. It is under Tools->Options->C++->Code Assistance
. Add the path where the my_global.h
is.
See this forum post.
Upvotes: 1
Reputation: 98436
I'm not sure in Windows, but in Linux you can use the mysql_config tool to get the correct flags to compile a client application:
For compiling:
$ mysql_config --cflags
-I/usr/include/mysql -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
And for linking:
$ mysql_config --libs
-Wl,-Bsymbolic-functions -rdynamic -L/usr/lib/mysql -lmysqlclient
Now, if you are using MinGW, options should be similar, probably dropping the *_LINUX ones.
My bet is that you are simply missing the -I<path_to_include_dir> bit.
Upvotes: 0