Hello, I have been trying to setup mysql API with C. I followed tutorials but I don't think I am installing the API correctly.

Could someone tell me the package to download, and what to do with it. Thank you very much.

Recommended Answers

All 6 Replies

Hello, I have been trying to setup mysql API with C. I followed tutorials but I don't think I am installing the API correctly.

Could someone tell me the package to download, and what to do with it. Thank you very much.

On this page you should find a link called Connector/C (libmysql)
A client library for C development.

http://dev.mysql.com/downloads/

Note if your trying to install this on a Linux box then use the appropriate package manager..

Thanks, but I still have an error when I compile.

Compiler: Default compiler
Building Makefile: "C:\Users\David\Desktop\Makefile.win"
Executing  make...
make.exe -f "C:\Users\David\Desktop\Makefile.win" all
g++.exe -c main.cpp -o main.o -I"C:/Dev-Cpp/include/c++"  -I"C:/Dev-Cpp/include/c++/mingw32"  -I"C:/Dev-Cpp/include/c++/backward"  -I"C:/Dev-Cpp/include"  -I"C:/Program Files/MySQL/MySQL Connector C 6.0.2/include"  

In file included from C:/Program Files/MySQL/MySQL Connector C 6.0.2/include/mysql.h:71,
                 from main.cpp:2:
C:/Program Files/MySQL/MySQL Connector C 6.0.2/include/mysql_com.h:268: 'SOCKET
   ' is used as a type, but is not defined as a type.

C:/Program Files/MySQL/MySQL Connector C 6.0.2/include/mysql_com.h:437: `SOCKET
   ' was not declared in this scope

C:/Program Files/MySQL/MySQL Connector C 6.0.2/include/mysql_com.h:437: parse 

   error before `,' token

make.exe: *** [main.o] Error 1

Execution terminated

I know compiling a C program with mysql in Linux is not standard. To give you an example here's a makefile

CFG=/usr/bin/mysql_config

test: test.c
	gcc test.c -o test `$(CFG) --cflags` `$(CFG) --libs`

Notice the CFG=/usr/bin/mysql_config

You should check on compiling instructions for your operating system.

I've been trying but nothing is working. I am using Dev-C++ in windows 7. I added the files to the compiler options, but same errors. Here is another compiler output.

71 C:\Program Files\MySQL\MySQL Connector C 6.0.2\include\mysql.h
In file included from C:/Program Files/MySQL/MySQL Connector C 6.0.2/include/mysql.h
2 C:\Users\David\Desktop\main.cpp
                 from main.cpp
268 C:\Program Files\MySQL\MySQL Connector C 6.0.2\include\mysql_com.h
'SOCKET
437 C:\Program Files\MySQL\MySQL Connector C 6.0.2\include\mysql_com.h
`SOCKET
437 C:\Program Files\MySQL\MySQL Connector C 6.0.2\include\mysql_com.h
parse 
 C:\Users\David\Desktop\Makefile.win
[Build Error]  [main.o] Error 1

The code I am running is this

#include <stdio.h>
#include <mysql.h>

int main(int argc, char **argv)
{
  printf("MySQL client version: %s\n", mysql_get_client_info());
}

youre compiling a C++ file.

Ok, its all fixed. That was one of the issues. Also out dated dev-cpp was messing with some stuff also. Thanks everyone for help.

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.