Menu

Using MySQL (mysql.h) on Windows

landrun
2009-02-20
2012-09-26
  • landrun

    landrun - 2009-02-20

    Okay, I've read the faq and the big 3 links.

    I've downloaded about a half a dozen mysql libraries. I've installed mysql 5.xxx??? just to get the mysql.h header file (and other associated files) and stayed up till 2am trying to get a simple program to compile -- to no avail.

    It seems as though I do not have all the header files I need to get Dev C++ to compile on a windows (Xp Pro) machine.

    I'm in the unfortunate position of not being able to post the exact error message or make files this morning (I can post them later this evening if required). But this is driving me crazy and I want to figure it out.

    I complied a simple 'hello mysql' program and got it running on a unix machine. This same code (and multiple sample programs I found on the internet) will not compile on my windows box. Its like the header files are different or something. Is there an obvious / simple thing I'm missing here?

    Thanks.

     
    • landrun

      landrun - 2009-02-24

      Well, I'm not sure if anyone is helping me, but I'm still working on my issue.

      I think I'm very close. I'm now getting the following error:

      variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.

      I read here: http://archives.devshed.com/forums/mysql-99/c-api-mysql-5t-2034573.html
      that I may need to convert the .dll file to a .a file. But I don't really understand how I'm supposed to do that or why etc...

      Can anyone help me out here?

      Thanks.

       
    • Wayne Keen

      Wayne Keen - 2009-02-20

      Well, is the error message indicating that it can't find a specific header?

      If not, are you linking the libraries you need to link. (I say this becuase many
      who come here think header files are all they need)

      Wayne

       
    • landrun

      landrun - 2009-02-20

      Thanks for the reply.

      Now that you've mentioned it, and I've thought about it a little, I did assume that when I downloaded the mysql.h and related .h files, that it was all I would need. I didn't stop to think that I might need to compile it into a library. I don't have the header files here, but if the functions are not in the header files, where is the c code that I would need to compile to create a library.

      I don't remember the exact error but I'm pretty sure it wasn't a missing header file. But, I could be wrong.

      At any rate, I guess the short version of my question is, "are you saying that I need to create a library from the header files I got when I downloaded mysql?" If so, I'm one of those ignorant people who thought I all needed was the header files. :o(

       
    • Wayne Keen

      Wayne Keen - 2009-02-20

      Please note that a header file is not something you compile into a library.

      A header file (in most cases) is like a menu, it tells you what the library provides. It usually contains no code that actually does anything. (Kind of like my brain that) The library is compiled code, it is the part that DOES the work.

      You need to include your header file, and link your library, in sperate steps. There is a discussion of the mechanics in all of this in the section in the "Please Read .." thread on the compile log, including headers and linking libraries.

      Wayne

       
    • landrun

      landrun - 2009-02-21

      Okay. I'm trying to compile the program with the library.

      I have some questions.

      First, there is no 'mysqlclient.a' library with my mysql installation. There is a 'mysqlclient.lib' in the lib directory of the insallation.

      I used the following command to compile the small program (show below) successfully on a unix box:
      c++ -Wall -I/usr/local/include/mysql -L/usr/local/lib/mysql mysqlcpp.cpp -o test.cgi -lmysqlclient

      BUT....

      For my windows box, I've tried to change that to:
      g++ -Wall -I"include\mysql" -L"lib\mysql\opt" mysqltest.cpp -o test.cgi -lmysqlclient

      I have created subdirectory in my devC++ include directory called mysql and put all the header files there. - because make was throwing an error and I read it was because make doesn't recognize spaces in file paths. - I have also created a subdirectory in my DevC++'s lib directory called mysql\opt and put the library files (they have .lib extension rather than '.a' - "I'm not sure that matters??)

      When I use the g++ -Wall -I"include\mysql" -L"lib\mysql\opt" mysqltest.cpp -o test.cgi -lmysqlclient

      Here is the actual program: (note: I've changed the header files to <iostream> etc.. for my windows box. The Unix box had these old header files on it.)

      I have spent hours on this and just want to figure out what I need to do to be able to access mysql from a c++ program. I'm close - I think, but need a little help.

      include <iostream.h>

      include <stdlib.h>

      include <stdio.h>

      include <mysql.h>

      define host "localhost"

      define username "cpplogin"

      define password "pass"

      define database "cppdb"

      MYSQL *conn;
      int code = 0;
      char typefood[] = "Main";
      char qry[255];

      int main(int argc, char *argv[])
      {

      // Don't crash the web browser. Print out the mime type: text\html
      std::cout << "Content-type: text/html\n\n";

      std::cout << "<html><title>Mysql and C++ !</title>";
      std::cout << "<body bgcolor='white'><font face='verdana' size='1'>";

      conn = mysql_init(NULL);

      mysql_real_connect(conn,host,username,password,database,0,NULL,0);

      MYSQL_RES res_set;
      MYSQL_ROW row;
      MYSQL_FIELD
      field;
      unsigned int i;

      sprintf (qry, "SELECT * FROM cpp");
      mysql_query(conn, qry);
      res_set = mysql_store_result(conn);

      unsigned int numrows = mysql_num_rows(res_set);
      cout << "Number of records returned: " << numrows << "<BR>";

      while ((row = mysql_fetch_row(res_set)) != NULL)
      for (i=0; i<mysql_num_fields(res_set); i++)
      if (row[i] != NULL)
      cout << "<BR>" << row[i] << " is this field's value.";

      cout << "<P>\n";
      cout << "<HR>\n";

      while((field = mysql_fetch_field(res_set)))
      {
      printf("field name %s\n", field->name);
      cout << "<BR>....";
      }

      return 0;
      

      }


       
    • landrun

      landrun - 2009-02-21

      Sorry! didn't finish the post above. The error I get when I use :

      g++ -Wall -I"include\mysql" -L"lib\mysql\opt" mysqltest.cpp -o test.cgi -lmysqlclient

      OR

      c++ -Wall -I"include\mysql" -L"lib\mysql\opt" mysqltest.cpp -o test.cgi -lmysqlclient

      I've used both, is:

      *** missing separator. Stop.

      Thanks.

       
    • landrun

      landrun - 2009-02-22

      Here's an update on my issue:

      I've read where there is a 'bug' in mysql.h here:
      http://www.mail-archive.com/mysql@lists.mysql.com/msg85359.html

      I have added the if endif structure as suggested.

      I'm also using a custom make program (other than the one autogenerated by dev c++) and I think I'm getting close. The program seems to complile completely but then I get errors at the end.
      I'm posting the source code (with the ifdef statement included as suggested in the link above) with my make program. I'll also post the compile log at the end. (at least the first part of it. It is very long)

      the source code:

      ifdef WIN32

      #include <windows.h>
      #include <winsock2.h>
      #pragma warning (disable: 4514 4786)
      #pragma warning( push, 3 )

      define VERSION "4.1"

      endif

      include <iostream>

      include <cstdlib>

      include <cstdio>

      include <mysql.h>

      define host "localhost"

      define username "cpplogin"

      define password "pass"

      define database "cppdb"

      using namespace std;

      MYSQL *conn;
      int code = 0;
      char typefood[] = "Main";
      char qry[255];

      int main(int argc, char *argv[])
      {

      // Don't crash the web browser. Print out the mime type: text\html
      std::cout << "Content-type: text/html\n\n";

      std::cout << "<html><title>Mysql and C++ !</title>";
      std::cout << "<body bgcolor='white'><font face='verdana' size='1'>";

      conn = mysql_init(NULL);

      //mysql_real_connect(conn,host,username,password,database,0,NULL,0);

      MYSQL_RES res_set;
      MYSQL_ROW row;
      MYSQL_FIELD
      field;
      unsigned int i;

      sprintf (qry, "SELECT * FROM cpp");
      mysql_query(conn, qry);
      res_set = mysql_store_result(conn);

      unsigned int numrows = mysql_num_rows(res_set);
      cout << "Number of records returned: " << numrows << "<BR>";

      while ((row = mysql_fetch_row(res_set)) != NULL)
      for (i=0; i<mysql_num_fields(res_set); i++)
      if (row[i] != NULL)
      cout << "<BR>" << row[i] << " is this field's value.";

      cout << "<P>\n";
      cout << "<HR>\n";

      while((field = mysql_fetch_field(res_set)))
      {
      printf("field name %s\n", field->name);
      cout << "<BR>....";
      }

      return 0;
      

      }


      the make file

      Project: MySQL

      Makefile created by Dev-C++ 4.9.9.2

      CPP = g++.exe
      CC = gcc.exe
      WINDRES = windres.exe
      RES =
      OBJ = mysqltest.o $(RES)
      LINKOBJ = mysqltest.o $(RES)
      LIBS = -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/lib/mysql/opt" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/include" -L"C:/Dev-Cpp/include/mysql"
      INCS = -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/mysql" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/lib/mysql/opt" -I"C:/Dev-Cpp/lib"
      CXXINCS = -I"C:/Dev-Cpp/lib/gcc/mingw32/3.4.2/include" -I"C:/Dev-Cpp/include/c++/3.4.2/backward" -I"C:/Dev-Cpp/include/c++/3.4.2/mingw32" -I"C:/Dev-Cpp/include/c++/3.4.2" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/include/mysql" -I"C:/Dev-Cpp/include" -I"C:/Dev-Cpp/lib/mysql/opt" -I"C:/Dev-Cpp/lib"
      BIN = MySQL.exe
      CXXFLAGS = $(CXXINCS)
      CFLAGS = $(INCS)
      RM = rm -f

      .PHONY: all all-before all-after clean clean-custom

      all: all-before MySQL.exe all-after

      clean: clean-custom
      ${RM} $(OBJ) $(BIN)

      $(BIN): $(OBJ)
      $(CPP) $(LINKOBJ) -o "MySQL.exe" $(LIBS) -lmysqlclient

      mysqltest.o: mysqltest.cpp
      $(CPP) -c mysqltest.cpp -o mysqltest.o $(CXXFLAGS)


      the start of the compile log

      Compiler: Default compiler
      Executing make...
      make.exe -f "kerryMakefile2.win" all
      g++.exe mysqltest.o -o "MySQL.exe" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/lib/mysql/opt" -L"C:/Dev-Cpp/lib" -L"C:/Dev-Cpp/include" -L"C:/Dev-Cpp/include/mysql" -lmysqlclient

      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/client.obj)(.debug$S+0xa2a):\build\mysql-5.0.4: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/client.obj)(.text[_mysql_read_default_options]+0x345): In function `mysql_read_default_options':
      f:\build\mysql-5.0:155: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.debug$S+0x5da):\build\mysql-5.0.4: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.

      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_get_argument]+0x79): In function get_argument': f:\build\mysql-5.0:25: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details. C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_search_default_file_with_ext]+0x1d2): In functionsearch_default_file_with_ext':
      f:\build\mysql-5.0:71: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_search_default_file_with_ext]+0x66f):f:\build\mysql-5.0:150: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_my_print_default_files]+0x68): In function `my_print_default_files':
      f:\build\mysql-5.0:10: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_my_print_default_files]+0xe2):f:\build\mysql-5.0:29: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.

      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_print_defaults]+0x13): In function print_defaults': f:\build\mysql-5.0:3: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details. C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_print_defaults]+0x31):f:\build\mysql-5.0:6: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details. C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_print_defaults]+0x3f):f:\build\mysql-5.0:7: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details. C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_print_defaults]+0x71):f:\build\mysql-5.0:15: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details. C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_print_defaults]+0x7f):f:\build\mysql-5.0:16: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details. C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_print_defaults]+0x8f):f:\build\mysql-5.0:17: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details. C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_my_search_option_files]+0x270): In functionmy_search_option_files':
      f:\build\mysql-5.0:94: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_my_search_option_files]+0x282):f:\build\mysql-5.0:104: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.

      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/default.obj)(.text[_load_defaults]+0x16c): In function load_defaults': f:\build\mysql-5.0:98: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details. C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/viosslfactories.obj)(.debug$S+0x262):\build\mysql-5.0.4: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details. C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/viosslfactories.obj)(.text[_vio_set_cert_stuff]+0x22): In functionvio_set_cert_stuff':
      f:\build\mysql-5.0:10: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.

      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/viosslfactories.obj)(.text[_vio_set_cert_stuff]+0x2c):f:\build\mysql-5.0:11: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/viosslfactories.obj)(.text[_vio_set_cert_stuff]+0x5c):f:\build\mysql-5.0:23: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/viosslfactories.obj)(.text[_vio_set_cert_stuff]+0x66):f:\build\mysql-5.0:24: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/viosslfactories.obj)(.text[_vio_set_cert_stuff]+0x8c):f:\build\mysql-5.0:39: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/viosslfactories.obj)(.text[_vio_set_cert_stuff]+0x96):f:\build\mysql-5.0:40: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/my_thr_init.obj)(.debug$S+0x2c6):\build\mysql-5.0.4: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/my_thr_init.obj)(.text[_my_thread_global_end]+0x8c): In function my_thread_global_end': f:\build\mysql-5.0:14: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details. C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/my_thr_init.obj)(.text[_my_thread_global_init]+0x2a): In functionmy_thread_global_init':
      f:\build\mysql-5.0:5: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/my_messnc.obj)(.debug$S+0x1f6):\build\mysql-5.0.4: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/my_messnc.obj)(.text[_my_message_no_curses]+0x1): In function `my_message_no_curses':
      f:\build\mysql-5.0:2: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/my_messnc.obj)(.text[_my_message_no_curses]+0x16):f:\build\mysql-5.0:7: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/my_messnc.obj)(.text[_my_message_no_curses]+0x2e):f:\build\mysql-5.0:11: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/my_messnc.obj)(.text[_my_message_no_curses]+0x39):f:\build\mysql-5.0: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/my_messnc.obj)(.text[_my_message_no_curses]+0x4f):f:\build\mysql-5.0:13: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/my_messnc.obj)(.text[_my_message_no_curses]+0x5a):f:\build\mysql-5.0:14: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.

      C:/Dev-Cpp/lib\mysqlclient.lib(./mysqlclient.dir/RelWithDebInfo/my_messnc.obj)(.text[_my_message_no_curses]+0x66):f:\build\mysql-5.0:15: variable '_iob' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.
      Warning: .drectve /DEFAULTLIB:&quot;uuid.lib&quot; /DEFAULTLIB:&quot;uuid.lib&quot; /DEFAULTLIB:&quot;LIBCMT&quot; /DEFAULTLIB:&quot;OLDNAMES&quot; ' unrecognized Warning: .drectve/DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"uuid.lib" /DEFAULTLIB:"LIBCMT" /DEFAULTLIB:"OLDNAMES" ' unrecognized

      .....


       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.