是否可以从库连接到mysql
Is it possible to connect to mysql from the library so?
在为外部应用程序编写我的第一个插件时,我遇到了很大的障碍。插件作为DLL文件加载(Linux的SO(尝试连接到数据库,但需要一些其他编译。到处都写有必要使用给定的命令编译应用程序:
gcc exa_7.c -o exa_7 -std=c99 `mysql_config --cflags --libs'
该命令是最正确的,但我无法组合到属性:-c -fPIC
当我尝试在不传递 MYSQL 所需的属性的情况下触发代码时,它会导致我很多错误:
dllmain.c:46:5: error: unknown type name ‘MYSQL’; did you mean ‘MYSQL_XID’?
MYSQL *MySQLConRet;
^~~~~
MYSQL_XID
dllmain.c:47:5: error: unknown type name ‘MYSQL’; did you mean ‘MYSQL_XID’?
MYSQL *MySQLConnection = NULL;
^~~~~
MYSQL_XID
dllmain.c:74:5: error: unknown type name ‘MYSQL_RES’; did you mean ‘MYSQL_XID’?
MYSQL_RES *mysqlResult = NULL;
^~~~~~~~~
MYSQL_XID
dllmain.c:90:6: error: unknown type name ‘MYSQL_ROW’; did you mean ‘MYSQL_XID’?
MYSQL_ROW mysqlRow;
^~~~~~~~~
MYSQL_XID
dllmain.c:91:6: error: unknown type name ‘MYSQL_FIELD’; did you mean ‘MYSQL_XID’?
MYSQL_FIELD *mysqlFields;
^~~~~~~~~~~
MYSQL_XID
我的清单包括:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <mysql/mysql.h>
#include <mysql/my_global.h>
#include <mysql/my_config.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include "ts3_functions.h"
#include "plugin.h"
#include <pthread.h>
//(more includes, but not important)
您知道如何解决此问题吗?
//编辑:删除#include <mysql/mysql.h>
的评论
现在我用命令编译了它:gcc -pthread -c -fPIC -o test.o dllmain.c
编译运行正常(没有任何错误(,但在运行时程序收到消息:undefined symbol: mysql_init
也许问题出在代码中?
MYSQL *MySQLConRet;
MYSQL *MySQLConnection = NULL;
MySQLConnection = mysql_init( NULL );
MySQLConRet = mysql_real_connect( MySQLConnection,
hostName,
userId,
password,
DB,
0,
NULL,
0 );
if ( MySQLConRet == NULL ) {
printf(mysql_error(MySQLConnection) );
exit(1);
}
您尚未包含<mysql/mysql.h>
.取消注释该行。此文件是使用 MySQL API 所必需的。 <mysql/my_global.h>
是一个内部头文件,用于包含公共系统头文件和定义实用程序宏 - 它不能替代<mysql/mysql.h>
,根本不应该直接包含。
相关文章:
- 无法在C++中建立与MySQL数据库的连接
- C++应用程序 MySQL odbc 数据库连接错误:在引发"otl_tmpl_exception<>"实例后终止调用
- MySQL 连接器/C++.尝试在此过程中停止连接到数据库
- 数据库连接并将数据从C ++程序保存到MySQL
- 为什么mysql拒绝本地连接
- 我不能使用 mysql 数据库连接同时使用插入和选择.C++
- mysql 远程连接 - mysql CL 客户端工作,C++应用程序不工作
- 从C++连接MySQL时程序错误中"error: stray ‘302’"编译错误
- 在Eclipse中找不到用于连接MySQL的C++代码的库
- 加载libmysql.dll连接mySQL数据库
- 连接mysql数据库c++
- 如何使用c++连接mySQL数据库
- 从c++连接MySQL:错误LNK2001:未解析的外部符号
- 使用c++和函数_main中引用的[ERROR]未解析的外部符号_mysql_error@4连接mysql
- Qt Creator _IMP连接MySql时出现错误
- 远程连接MySQL是安全的吗?
- 使用eclipse在c++中连接mysql
- 如何使用c++连接mysql
- 从c++连接mysql最好的框架是什么?
- 使用Poco连接MySQL失败