【问题标题】:Creating a test database in MySQL through C通过 C 在 MySQL 中创建测试数据库
【发布时间】:2012-03-10 02:55:23
【问题描述】:

我在尝试编译以下代码时遇到编译错误。

#include "my_global.h"
#include "mysql.h"

int main(void)
{
   MYSQL *conn;
   conn = mysql_init(NULL);
   if (conn == NULL) {
         printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
         exit(1);
   }

   if (mysql_real_connect(conn, "localhost", "zetcode",
          "passwd", NULL, 0, NULL, 0) == NULL) {
      printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }

  if (mysql_query(conn, "create database testdb")) {
      printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }


  mysql_close(conn);

  return 0;
}

我在 Windows 7 上使用 Borland 32 位编译器来编译以下代码。我的编译命令如下所示

c:\Borland\BCC55>bcc32 -Ic:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2
-win32-vs2005\include -c creatingTESTDB.c

我收到六个编译错误:

Borland C++ 5.5.1 for Win32 版权所有 (c) 1993, 2000 Borland createdTESTDB.c:
警告 W8017 c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs20 05\include\config-win.h 111: 'S_IRWXU' 的重新定义不是 相同

错误 E2238 c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005 \include\config-win.h 114: 'mode_t' 的多重声明

错误 E2344 c:\Borland\Bcc55\include\sys/types.h 35:较早 'mod e_t' 的声明

错误 E2141 c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005 \include\config-win.h 265:函数中的声明语法错误 double2ulonglong

错误 E2378 c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005 \include\config-win.h 268: 缺少返回语句;在功能上 double2ulonglo ng

错误 E2293 c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005 \include\my_global.h 1591:) 函数 rint

中预期错误 E2293 c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005 \include\my_global.h 1595:) 函数 rint

* 编译时出现 6 个错误 *

任何帮助将不胜感激。 我在尝试编译以下代码时遇到编译错误。

#include "my_global.h"
#include "mysql.h"

int main(void)
{
   MYSQL *conn;
   conn = mysql_init(NULL);
   if (conn == NULL) {
         printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
         exit(1);
   }

   if (mysql_real_connect(conn, "localhost", "zetcode",
          "passwd", NULL, 0, NULL, 0) == NULL) {
      printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }

  if (mysql_query(conn, "create database testdb")) {
      printf("Error %u: %s\n", mysql_errno(conn), mysql_error(conn));
      exit(1);
  }


  mysql_close(conn);

  return 0;
}

我在 Windows 7 上使用 Borland 32 位编译器来编译以下代码。我的编译命令如下所示

c:\Borland\BCC55>bcc32 -Ic:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2
-win32-vs2005\include -c creatingTESTDB.c

我收到六个编译错误:

Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
creatingTESTDB.c:<br> Warning W8017
c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs20
05\include\config-win.h 111: Redefinition of 'S_IRWXU' is not
identical<br><br> Error E2238
c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005
\include\config-win.h 114: Multiple declaration for 'mode_t'<br><br>
Error E2344 c:\Borland\Bcc55\include\sys/types.h 35: Earlier
declaration of 'mod e_t'<br><br> Error E2141
c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005
\include\config-win.h 265: Declaration syntax error in function
double2ulonglong<br><br> Error E2378
c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005
\include\config-win.h 268: Return statement missing ; in function
double2ulonglo ng<br><br> Error E2293
c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005
\include\my_global.h 1591: ) expected in function rint<br><br> Error
E2293
c:\Users\osho\Desktop\mysql-connector-c-noinstall-6.0.2-win32-vs2005
\include\my_global.h 1595: ) expected in function rint<br><br>
*** 6 errors in Compile ***

我该如何解决这个问题?

【问题讨论】:

    标签: mysql c


    【解决方案1】:

    您没有提供您正在使用的 MySQL 版本。尝试添加以下标题:

    #include "my_sys.h"
    

    其他要查看的来源是:

    【讨论】:

    • 我使用的是mysql5.5.20版本的mysql。包含my_sys.h后,错误也没有变化。我已经浏览了链接,但它适用于 Unix 系统,我使用的是 windows 和 borland 编译器而不是 gcc。如果可能,请提供更多信息。
    猜你喜欢
    • 1970-01-01
    • 2014-06-07
    • 2012-10-05
    • 2011-01-14
    • 2013-12-22
    • 2019-05-20
    • 1970-01-01
    • 2021-07-24
    • 1970-01-01
    相关资源
    最近更新 更多