代码改变世界

mysql++ 安装

2015-10-14 22:52  youxin  阅读(2068)  评论(0编辑  收藏  举报

官网介绍:

http://www.tangentsoft.net/mysql++/

MySQL++ is a C++ wrapper for MySQL’s C API. It is built around the same principles as the Standard C++ Library, to make dealing with the database as easy as dealing with STL containers. In addition, MySQL++ provides facilities that let you avoid the most repetitive sorts of SQL within your own code, providing native C++ interfaces for these common tasks.

MySQL++ should work on any platform that has a Standard C++ compiler and the MySQL C API development files. The code does use some C99/TR1 features that are widely supported in advance of full standardization, but these are optional.

 

 

linux安装:

tar -xvzf mysql++xxx.tar.gz

进入解压后的目录,一大堆文件,惯例------先看README,因为我的是ubuntu,所以就看README-Linux.txt

To build MySQL++, you must have the MySQL C API development
files installed.

On Unixy systems (Linux, Mac OS X, Cygwin, *BSD, Solaris...),
the MySQL development files are installed if you build MySQL
from source. If you installed MySQL as a binary package, then
the development files are often packaged separately from the
MySQL server itself. It's common for the package containing the
development files to be called something like "MySQL-devel".

If you're building on Windows with Visual C++ or MinGW, you
need to install the native Win32 port of MySQL from mysql.com.
The development files are only included with the "complete"
version of the MySQL installer, and some versions of this
installer won't actually install them unless you do a custom
install. Another pitfall is that MySQL++'s project files assume
that you've installed the current General Availability release of
MySQL (v5.0 right now) and it's installed in the default location.
If you've installed a different version, or if MySQL Inc. changes
the default location (which they seem to do regularly!) you'll have
to adjust the link and include file paths in the project settings.

 

首先它告诉你,mysql++必须得有mysql c API才能正常工作,mysql c API就需要安装mysqlclient.

ubuntu下面执行下面命令就可以

sudo apt-get install libmysqlclient-dev

 其次它告诉你,为了防止动态链接器找不见,最好不要装在非主流的目录下,它建议你放/usr下面

./configure --prefix=/usr

执行建议的命令,它就开始检测文件,配置了.

(提示找不到:: Didn't find mysqlclient library 。手动指定,

./configure --prefix=/usr --with-mysql-lib=/usr/lib/x86_64-linux-gnu

我在xampp目录下找到了,指定为: --with-mysql-lib=/opt/lampp/lib 就行了。

make。make install

root@make install
mkdir -p /usr/lib
/usr/bin/install -c -m 644 libmysqlpp.so /usr/lib
/usr/bin/install -c libmysqlpp.so.3.2.2 /usr/lib
(cd /usr/lib ; rm -f libmysqlpp.so libmysqlpp.so.3; ln -s libmysqlpp.so.3.2.2 libmysqlpp.so.3; ln -s libmysqlpp.so.3 libmysqlpp.so)
mkdir -p /usr/include/mysql++
(cd . ; /usr/bin/install -c -m 644 lib/*.h /usr/include/mysql++)

去example下找个例子测试下:

编译simple1.cpp

g++ -o simple1 simple1.cpp
simple1.cpp:28:21: fatal error: cmdline.h: No such file or directory
#include "cmdline.h"
^
compilation terminated.

locate cmdline.h一下,发现在/usr/include/mysql++/cmdline.h,

g++ -o simple1 simple1.cpp  -I  /usr/include/mysql++

又报错:

/usr/include/mysql++/common.h:133:28: fatal error: mysql_version.h: No such file or directory
# include <mysql_version.h>

我电脑是上mysql头文件是在/opt/lampp/include目录下的。(一般是在/usr/include/mysql下)。

g++ -o test simple1.cpp -I /usr/include/mysql++/ -I /usr/include/mysql -lmysqlpp

 类似这样。

g++ -o simple1 simple1.cpp  -I  /usr/include/mysql++  -I /opt/lampp/include -lmysqlpp

ok,终于成功了。

执行完成,有错误,说:

connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock

我用的是xampp,locate下mysql.sock文件,然后创建个软link就行了。

ln -s  /opt/lampp/var/mysql/mysql.sock /var/run/mysqld/mysqld.sock

(plus:在mysql的配置文件里,/opt/lampp/etc/my.cnf, 发现了这样的配置:

 
[java] 
<span style="font-size:24px;"># The following options will be passed to all MySQL clients  
[client]  
#password       = your_password  
port            = 3306  
socket          = /opt/lampp/var/mysql/mysql.sock  
  
# Here follows entries for some specific programs  
  
# The MySQL server  
[mysqld]  
user            = nobody  
port            = 3306  
socket          = /opt/lampp/var/mysql/mysql.sock  
  这个是我们自己可以改动的)
 
 

参考:http://www.cnblogs.com/comoon/p/4104482.html?utm_source=tuicool

 

windows安装:

下载mysql++的源码,然后打开解决方案,vc2008或者vc2005里面,编译之后就能看见几个dll和lib文件,lib是编译时需要的,而dll是你运行时需要的。

编译mysqlpp项目报错:

>d:\my documents\visual studio 2008\projects\testmysql\testmysql\mysql\mysql_com.h(191) : error C2146: 语法错误 : 缺少“;”(在标识符“fd”的前面)
>d:\my documents\visual studio 2008\projects\testmysql\testmysql\mysql\mysql_com.h(191) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
>d:\my documents\visual studio 2008\projects\testmysql\testmysql\mysql\mysql_com.h(191) : error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
>d:\my documents\visual studio 2008\projects\testmysql\testmysql\mysql\mysql_com.h(366) : error C2065: “SOCKET”: 未声明的标识符
>d:\my documents\visual studio 2008\projects\testmysql\testmysql\mysql\mysql_com.h(366) : error C2146: 语法错误 : 缺少“)”(在标识符“s”的前面)
>d:\my documents\visual studio 2008\projects\testmysql\testmysql\mysql\mysql_com.h(367) : error C2059: 语法错误 : “)”

我的改动是:在mysql_com.h前面加#include<windows.h>

又报错:

error LNK2001: 无法解析的外部符号 mysql_thread_init
1>sqlstream.obj : error LNK2001: 无法解析的外部符号 mysql_thread_init

http://blog.csdn.net/tastelife/article/details/5291725

http://blog.csdn.net/eckelwei/article/details/8536767