Anyone creating programs using the MySQL C api using Cygwin?

Mikael Åsberg mikas493@student.liu.se
Wed Jan 12 12:01:00 GMT 2005


Hello, I installed a native windows version of MySQL (4.1.18) and tried to 
compile a C program using the MySQL C API using GCC (version 3.3.3 cygwin 
special). The program compiles and links without any errors or warnings 
(maximum warning level, c99-mode) but segfaults near the end. I haven't been 
able to reproduce the segfault using linux...so my question is: I am silly 
thinking I could use a native Windows version of MySQL with Cygwin without 
any problems? I guess I could use MSVC++, of which I own a legitimate copy, 
but I am trying to use it as little as possible.
Here's the Makefile I used for my simple test program:
CC = gcc
LD = gcc
CFLAGS = -std=c99 -Wall -W -pedantic -g -Ic:/mysql/include -c -o
LDFLAGS = -Lc:/mysql/lib/opt -lmysql -o $(EXEC)
EXEC = wizard_spells.exe
OBJECTS = wizard_spells.o

all: $(OBJECTS)
 $(LD) $(OBJECTS) $(LDFLAGS)

%.o: %.c
 $(CC) $(CFLAGS) $@ $<

clean:
 rm -f $(OBJECTS) $(EXEC) *~ *.stackdump

I haven't tampered with the mysql libraries at all btw.

Here's the actual test program:
#include <mysql.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static MYSQL m;

void create_chemistry_recipe_table(void);

int main(void)
{
   const char *host = "localhost";
   const char *user = "root";
   const char *password = "andromeda";
   const char *database = "spells";

   if(!mysql_init(&m))
   {
      fprintf(stderr, "mysql_init() failed.\n");

      return EXIT_FAILURE;
   }

   if(!mysql_real_connect(
         &m,
         host,
         user,
         password,
         database,
         0,
         NULL,
         0
         )
      )
   {
      fprintf(stderr, "%s\n", mysql_error(&m));

      return EXIT_FAILURE;
   }
   else
   {
      printf("Connection successful.\n");
   }

   create_chemistry_recipe_table();

   printf("calling mysql_close()\n");

   mysql_close(&m);

   return EXIT_SUCCESS;
}

void
create_chemistry_recipe_table(void)
{
   if(mysql_query(&m, "CREATE TABLE chemistry_recipes "
                  "(name VARCHAR(64),  primary_components "
                  "VARCHAR(64))") == 0)
   {
      printf("Chemistry table successfully created.\n");
   }
   else
   {
      printf("Failed to create chemistry recipe table.\n"
              "Error code: %u\n"
              "Description: %s\n", mysql_errno(&m), mysql_error(&m));
   }
}

And, finally, the output:
$ ./wizard_spells.exe
Connection successful.
Failed to create chemistry recipe table.
Error code: 1050
Description: Table 'chemistry_recipes' already exists
Segmentation fault (core dumped)

Thanks for any replies and I'm sorry if this is off-topic. I thought about 
if I should post on a MySQL list or on a Cygwin list and I decided to post 
here in the end.

/ Mikael 



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/



More information about the Cygwin mailing list