简体   繁体   English

mysql_init()始终返回null

[英]mysql_init() always return null

I have this very short program. 我有这个非常短的节目。 For some reason mysql_init always returns null for me. 出于某种原因,mysql_init总是为我返回null。 According to the documentation, this happens if there isn't enough memory. 根据文档,如果内存不足,就会发生这种情况。 How can this be? 怎么会这样? It's just these few lines of code. 这只是几行代码。

#include "mysql.h"

int main()
{
    MYSQL * mysql;
    mysql = mysql_init(0);
    // here mysql is 0
    return 0;
}

I use Visual Studio 2015 and the lib from mariadb-10.1.8-win32.zip . 我使用Visual Studio 2015和mariadb-10.1.8-win32.zip中的lib。

edit: I made it work a bit. 编辑:我做了一点工作。 I was compiling with debug Settings in visual Studio and linked to libmysqld.lib. 我正在使用Visual Studio中的调试设置进行编译并链接到libmysqld.lib。 I also copies libmysqld.dll in the work dir. 我还在工作目录中复制libmysqld.dll。 That resulted in the ffect I describe above. 这导致我上面描述的效果。 I tried to link to libmysql.lib and copies libmysql.dll to the work dir and that worked. 我试图链接到libmysql.lib并将libmysql.dll复制到工作目录,这是有效的。 I don't plan to debug mysql code, so I can live with that. 我不打算调试mysql代码,所以我可以忍受。 It's still strange though why the debug lib doesn't work for the same code. 虽然调试库不适用于相同的代码,但仍然很奇怪。

if you link with libmysqld.lib, mysql_init will return NULL or crash. 如果你链接libmysqld.lib,mysql_init将返回NULL或崩溃。 I test on mysql5.6 5.7 win10 vs2017. 我测试了mysql5.6 5.7 win10 vs2017。

the correct is libmysql.lib. 正确的是libmysql.lib。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM