【问题标题】:C MySQL API compiler warning problem with redefinition while including header files包含头文件时重新定义的C MySQL API编译器警告问题
【发布时间】:2011-04-27 13:21:19
【问题描述】:

我正在编译一个简单的c程序来测试eclipse cygwin环境mysql-connector-c-6.0.2中包含的库文件 程序

#include <my_global.h>
#include <mysql.h>
int main(int argv,char* argc[])
{
        printf("my SQL libraries successfully included\n");
    return 0;
}

我得到编译器错误

cygwin warning:
  MS-DOS style path detected: C:\MinGW\Workspace\sql_test\Debug
  Preferred POSIX equivalent is: /cygdrive/c/MinGW/Workspace/sql_test/Debug
  CYGWIN environment variable option "nodosfilewarning" turns off this warning.
  Consult the user's guide for more details about POSIX paths:
    http://cygwin.com/cygwin-ug-net/using.html#using-pathnames
In file included from ../sql_test.c:8:
D:\mysql-connector-c-6.0.2\include/my_global.h:1416:1: warning: "floatget" redefined
D:\mysql-connector-c-6.0.2\include/my_global.h:1232:1: warning: this is the location of the previous definition
D:\mysql-connector-c-6.0.2\include/my_global.h:1417:1: warning: "floatstore" redefined
D:\mysql-connector-c-6.0.2\include/my_global.h:1231:1: warning: this is the location of the previous definition
D:\mysql-connector-c-6.0.2\include/my_global.h:1418:1: warning: "doubleget" redefined
D:\mysql-connector-c-6.0.2\include/my_global.h:1220:1: warning: this is the location of the previous definition
D:\mysql-connector-c-6.0.2\include/my_global.h:1419:1: warning: "doublestore" redefined
D:\mysql-connector-c-6.0.2\include/my_global.h:1225:1: warning: this is the location of the previous definition
Finished building: ../sql_test.c

我已经验证了my_global.h文件,这些减速似乎是有效的。

  1. 如何解决这些重定义错误?
  2. 在 Eclipse 中的位置以及如何设置此“CYGWIN 环境变量选项“nodosfilewarning”以关闭此警告”。

这里可以看到

的头文件my_global.h

【问题讨论】:

  • 编译器指出重复的确切行。这不正确吗?
  • :|抱歉没有超载。我已将链接粘贴到头文件。我假设源文件应该没有问题,因为它是 oracle 给出的 mysql c 连接器的标头。
  • 他们确实定义了相同的宏,具体取决于其他一些宏(可能来自配置?)。我无法通过 1000 行嵌套的#ifdefs,所以不能确切地说出了什么问题。
  • 您可能进行了 grep/函数搜索。您说他们依赖 #ifdefs 是对的。您将如何运行此程序?你能检查一下吗? dev.mysql.com/downloads/connector/c/#downloads 包含在项目中并编译。

标签: mysql c eclipse compiler-warnings


【解决方案1】:

对于警告,在操作系统环境(控制面板->系统->高级->环境变量)中定义CYGWIN=nodosfilewarning。如果这不起作用,请尝试注销以确保没有使用旧环境。

对于重新定义错误,正如 Bo 所说,编译器会准确地告诉您错误在哪里。如果您不理解它们,那么您至少应该将这些行作为您问题的一部分发布。

【讨论】:

  • 我已经发布了指向头文件的链接。您能告诉我需要什么样的编译器设置吗?它是 sql c 连接的标准库。
  • 这取决于你想要什么样的行为。您需要仔细检查其中的所有 #ifdef/#else/#endif 声明,以确定您认为应该包含哪些部分,然后确定供应商为何将其设计为包含相同 #define 的不同版本。
  • 好吧,我注释掉了重新定义的函数。并在该点留下一个标记,以检查将来是否有任何中断。
猜你喜欢
  • 2013-01-03
  • 1970-01-01
  • 2014-05-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多