0

以前有人做过吗???

我正在尝试使用 MinGW 编译使用 MySQL 库的程序。我不断收到重新定义函数“rint”的消息。好的,该函数确实在来自 MySQL 的 config-win.h 和来自标准库的 math.h 两个文件中,但它们都应该是没有问题的库。

在打破我的头一段时间后,我什至尝试了这个,它不会编译:

#include <iostream>
#include <my_global.h>
#include <mysql.h>
using namespace std;

int main() {
    cout << "Hello World!!!" << endl; // prints Hello World!!!
    return 0;   
}

这是命令以及我为编译而发出的输出

i586-mingw32msvc-cc -I/usr/include/mysql probando.cpp -w

In file included from /usr/include/mysql/my_global.h:73,
                 from probando.cpp:10:
/usr/include/mysql/config-win.h: In function ‘double rint(double)’:
/usr/include/mysql/config-win.h:229: error: redefinition of ‘double rint(double)’
/usr/lib/gcc/i586-mingw32msvc/4.2.1-sjlj/../../../../i586-mingw32msvc/include/math.h:635: error: ‘double rint(double)’ previously defined here

我已经在 WindowsXP 中使用 MinGW 进行了测试,MySQL 库在 .a 库中正确转换,在 Linux 中(输出来自 Linux,与 Windows 中几乎相同)使用 MinGW32。

人们......我没有选择......任何线索?有人以前使用过 MySQL 和 MinGW 吗?它可以与 Cygwin 一起使用吗?

如果您花时间回答,请提前致谢。

4

3 回答 3

1

也是一个猜测,但似乎 math.h 和 config-win.h 有一个名为 rint 的函数,请确保没有两个具有相同名称的函数。

顺便说一句,因为我不完全确定,我正在使这个社区可编辑,如果我不正确,请随时编辑这篇文章。

于 2008-10-07T12:23:15.907 回答
0

好的,我解决了。

我的愚蠢是包括错误的文件。要在 mingw 中执行此操作,您必须 #include <windows.h> 而不是 <config-win.h>

不管怎么说,还是要谢谢你!!!

于 2008-10-09T16:26:12.797 回答
0

我不知道有问题的堆栈,但我的猜测是 math.h 会以某种方式被包含在内。查看 math.h 文件。在靠近顶部的某个地方应该有一个包含防护。如果您不熟悉包含保护的概念,请点击链接。在这两个地方,您都应该使用包含守卫来包含 math.h。

您还可以查找特定于 Linux 的#define;由于某处的#define,该文件可能不会在Linux上包含两次。

正如我所说,这只是一个猜测。

于 2008-10-07T11:31:46.667 回答