我想用
linux中的C连接到
mysql数据库.在我的本地机器上,我正在运行Ubuntu,并安装了mysql服务器和客户端软件包:
sudo apt-get install mysql-server mysql-client
我遇到了Mysql++,但是从他们的二进制包运行./configure时遇到了一些问题.错误说:
checking for MySQL library directory… configure: error: Didn’t find mysqlclient library in ‘/usr/lib64 /usr/lib /usr/lib64/mysql /usr/lib/mysql /usr/local/lib64 /usr/local/lib /usr/local/lib/mysql /usr/local/mysql/lib /usr/local/mysql/lib/mysql /usr/mysql/lib/mysql /opt/mysql/lib /opt/mysql/lib/mysql /sw/lib /sw/lib/mysql’
我看到我可以使用此命令指定路径:
./configure –with-mysql-lib=/…
但我不知道在哪里指出它.我使用whereis mysql但找不到任何包含lib子目录的mysql目录. mysqlclient库在哪里安装?
编辑:
找到libmysqlclient后我回来了
/usr/lib/i386-linux-gnu/libmysqlclient.so.18 /usr/lib/i386-linux-gnu/libmysqlclient.so.18.0.0 /usr/lib/i386-linux-gnu/libmysqlclient_r.so.18 /usr/lib/i386-linux-gnu/libmysqlclient_r.so.18.0.0 /usr/share/doc/libmysqlclient18 /usr/share/doc/libmysqlclient18/changelog.Debian.gz /usr/share/doc/libmysqlclient18/copyright /var/cache/apt/archives/libmysqlclient18_5.5.22-0ubuntu1_i386.deb /var/lib/dpkg/info/libmysqlclient18:i386.list /var/lib/dpkg/info/libmysqlclient18:i386.md5sums /var/lib/dpkg/info/libmysqlclient18:i386.postinst /var/lib/dpkg/info/libmysqlclient18:i386.postrm /var/lib/dpkg/info/libmysqlclient18:i386.shlibs
所以,我尝试了./configure –with-mysql-lib = /usr/lib / i386-linux-gnu,似乎完成没有任何抱怨.
虽然这解决了完成./configure完成的问题,但我仍然有进一步的麻烦.当我跑步时让事情变好,直到这一点:
In file included from ./lib/sql_buffer.h:31:0, from ./lib/sql_buffer.cpp:26: ./lib/refcounted.h:258:2: error: ‘size_t’ does not name a type ./lib/refcounted.h: In constructor ‘mysqlpp::RefCountedPointer::RefCountedPointer()’: ./lib/refcounted.h:89:2: error: class ‘mysqlpp::RefCountedPointer’ does not have any field named ‘refs_’ ./lib/refcounted.h: In constructor ‘mysqlpp::RefCountedPointer::RefCountedPointer(T*)’: ./lib/refcounted.h:100:2: error: class ‘mysqlpp::RefCountedPointer’ does not have any field named ‘refs_’ ./lib/refcounted.h:104:4: error: ‘refs_’ was not declared in this scope ./lib/refcounted.h:104:16: error: expected type-specifier before ‘size_t’ ./lib/refcounted.h:104:16: error: expected ‘;’ before ‘size_t’ ./lib/refcounted.h: In constructor ‘mysqlpp::RefCountedPointer::RefCountedPointer(const ThisType&)’: ./lib/refcounted.h:112:2: error: class ‘mysqlpp::RefCountedPointer’ does not have any field named ‘refs_’ ./lib/refcounted.h:115:8: error: ‘refs_’ was not declared in this scope ./lib/refcounted.h: In destructor ‘mysqlpp::RefCountedPointer::~RefCountedPointer()’: ./lib/refcounted.h:125:7: error: ‘refs_’ was not declared in this scope ./lib/refcounted.h: In member function ‘void mysqlpp::RefCountedPointer::swap(mysqlpp::RefCountedPointer::ThisType&)’: ./lib/refcounted.h:246:13: error: ‘refs_’ was not declared in this scope make: *** [mysqlpp_sql_buffer.o] Error 1
我不是很熟悉C,所以我不确定错误究竟是什么意思.如何从这一点获得Mysql设置的任何帮助或指导将非常感激.虽然,我承认我也开始寻找可供使用的替代库.
解决方法
导致此问题的原因是size_t在配置(make)文件中调用之前依赖于stddef命名空间的包含.
我有同样的问题(使用亚马逊EC2 ubuntu 12.04云服务器)并通过编辑有问题的文件(在我的情况下,sql_buffer.cpp位于/ home / ubuntu / mysql -3.1.0 / lib)并包括stddef来解决它(同时还要移动字符串命名空间):
#include <stddef.h>
#include <string.h>
#include "sql_buffer.h"
这个更正回答了你的问题.但是,你可能还有其他问题,就像我一样.所以我解释了我是如何解决你可能会或可能不会遇到的一些后续问题的.
你可能不得不使用
sudo chown username sql_buffer.cpp
能够编辑文件,具体取决于您的安装设置(例如,我是用户ubuntu).
然后我遇到了另一个问题:
./ssx/genv2.cpp: In function bool generate_ssqls2(const char*,const ParseV2*):
./ssx/genv2.cpp:70:28: error: strcmp was not declared in this scope
所以我编辑了违规文件(genv2.cpp)并包含了字符串命名空间
#include <string.h>
然后我有另一个问题:
./libmysqlpp_ssqls2parse.a(ssqls2parse_parsev2.o): In function `Type':
/home/ubuntu/mysql++-3.1.0/./ssx/parsev2.cpp:256: undefined reference to `mysqlpp::internal::str_to_lwr
我本可以编辑Makefile.in但是选择只是在命令行中运行:
sudo g++ -o test_ssqls2 test_ssqls2_ssqls2.o -lmysqlpp_ssqls2parse -L. -lmysqlclient -L/usr/lib/x86_64-linux-gnu -lmysqlpp
然后我继续制作过程.
这对我有用:安装并运行mysql. (编辑:台州站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|