I am new to conneting to MYSQL through a C++ code; so this is what i did

i installed MySQL Server 5.1 (it was a EXE), and thats it. i opened the MYSql command line client and created a DB, and added a table and values to it.

This is my code in C++ (I'm using VS2008)

#include "stdafx.h"
#include <iostream>
#include <mysql.h>
#include <windows.h>


int _tmain(int argc, _TCHAR* argv[])
{
	
	return 0;
}

I get an error that prints fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory What have i done wrong.. can some one help me fix this ASAP.

Dani AI

Generated

Short answer: the compiler can’t find the MySQL client headers (that’s what C1083 means). added #include <mysql.h> but Visual Studio doesn’t know where your MySQL headers live, or the headers weren’t installed at all. was right to point at the include-path, and ’s reminder about linking is also important — you need both headers and the client library files. (docs.oracle.com)

What to check (quick): search your disk for mysql.h (Windows Explorer or PowerShell). If you find it under your MySQL installation, note that folder (for older installers it’s typically under your MySQL install ...\include). If you don’t find it, install the MySQL C client / Connector (the Connector/C or the C API package) — it provides the headers and the libmysql libraries. Download page: MySQL Connector/C. (dev.mysql.com)

How to configure Visual Studio (prefer per‑project): open Project → Properties → Configuration Properties → C/C++ → General → Additional Include Directories and add the folder that contains mysql.h. Then go to Linker → General → Additional Library Directories and add the MySQL lib folder; finally add libmysql.lib (or the appropriate import/static lib) to Linker → Input → Additional Dependencies. Set the settings for All Configurations/All Platforms (or repeat for Debug/Release). This per‑project method is preferred over global VC++ Directories. (learn.microsoft.com)

Runtime and troubleshooting tips: match bitness — 32‑bit libs require a Win32 build, 64‑bit libs require x64. If you link the import lib (libmysql.lib) the program still needs libmysql.dll available at run time (put it in the EXE folder or on PATH). If you still get C1083 after adding an include path, double‑check you edited the same project configuration that you are building (Debug vs Release, Win32 vs x64). For reference read the MySQL C API docs and the Connector download notes. (stackoverflow.com)

Recommended reads: MySQL 5.1 Reference Manual — Compiling MySQL Clients on Windows and the Connector/C downloads page linked above. These explain header order, the import/static libs, and runtime DLLs in detail. (docs.oracle.com)

Recommended Answers

All 5 Replies

Hi,

first of all, this post does not belong here. This is a C++ discussion thread and not about specific IDE-s or tools. How ever, your problem is that your compiler, actually your preprocessor does not know where to look for the mysql.h file. You either have to prepend the full or relative path to the mysql.h file in the include directive or to tell VS2008 where to look for mysql include files. That is, go to Tools --> Options --> Projects and Solutions --> VC++ Directories and set the mysql Include directories path or paths.

best regards

>> first of all, this post does not belong here

Actually: it does. It's about C++, so it belongs in the C++ forum.

That is, go to Tools --> Options --> Projects and Solutions --> VC++ Directories and set the mysql Include directories path or paths.

I am still stuck here. I am not sure as what path do i have to add here. I can't find a mysql.h file anywhere. Can some one please copy paste the path so that it would help me to find out what i am lacking.

It's like if you were trying to jump steps.

What library are you using to interact with an SQL database? If your answer is none... Then you need to learn how to link and use libraries with your compiler. If there's a lib or API you're using. What you need is there. Read the documentation!

commented: Good observation +5

As far as I can see, before you continue with mySQL programming, you should first go through some C++ beginners tutorials. There are some really nice tutorials on the net. Use google, it's a mighty tool.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.